Replace

TwinCAT TIA
Tools String functions

ns=2;s=DEPRAG Smart/Utilities/StringOperations/Replace

Replaces all occurrences of a specified string in a text with another one.

Parameters:

    OldString
    The text that will be replaced by NewString in StringToReplaceIn.
    NewString
    The text is inserted into StringToReplaceIn instead of OldString.
    IgnoreCase
    A boolean variable that specifies whether case should be ignored when comparing or not.

Returns:

    Replace
    A structure variable of type OpcMethodReturnValueString. The Result property contains the command-specific return values.
      Result
      The text StringToReplaceIn by replacing all old characters (parameter OldString) with the new text (parameter NewString).

Examples:

In addition to the parameters already explained, the following variables must be created / transferred for the implementation in TwinCAT 3:

Beckhoff parameter:

    bStringReplace
    A boolean variable that can be used to trigger the execution of the Replace command.
    OutputDataStringReplace
    An instance of the "ST_StringOutputData" structure into which the return value of the Replace method is written.
    hrStringReplace
    This can be used to monitor the execution of the command. Error codes have the type "HRESULT".
    fbStringOperations
    An instance of the "FB_StringOperations" function block supplied with the DEPRAG Smart library.
    StringToReplaceIn
    The text in which one text is replaced by another.
    StringToReplaceInLength
    The length of the string in which one string is to be replaced by the other.
    OldString
    The text that will be replaced by NewString in StringToReplaceIn.
    OldStringLength
    The length of the old string whose occurrences are to be replaced by a new string.
    NewString
    The text is inserted into StringToReplaceIn instead of OldString.
    NewStringLength
    The length of the new string to replace each occurrence of the old string.
    IgnoreCase
    A boolean variable that specifies whether case should be ignored when comparing or not.
    ConnectionHandle
    "ConnectionHandle" received when establishing a connection between DEPRAG Smart Server and your OPC UA client.


VAR
    bStringReplace   : BOOL;
    OutputDataStringReplace : ST_StringOutputData;
    hrStringReplace   : HRESULT;

    fbStringOperations : FB_StringOperations;
END_VAR

hrStringReplace := fbStringOperations.StringReplace(
      bExecute     := bStringReplace, 
      ConnectionHandle  := depragSmartConnection.ConnectionHandle,
      StringToReplaceIn  := 'IamATestString',
      StringToReplaceInLength := SIZEOF('IamATestString'),
      OldString    := 'Test',
      OldStringLength   := SIZEOF('Test'),
      NewString    := 'Beautiful',
      NewStringLength   := SIZEOF('Beautiful'),  
      IgnoreCase    := TRUE, 
      OutputData    => OutputDataStringReplace);
IF hrStringReplace <> S_FALSE THEN 
      bStringReplace := FALSE;
END_IF
                                                    

For examples and explanations regarding the calls of nodes via Siemens TIA Portal please refer to the sub-menu "Siemens TIA Portal" in section "Getting Started".