IndexOf

TwinCAT TIA
Tools String functions

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

Searches for a text in another text and returns the zero-based position of the first occurrence.

Parameters:

Returns:

    IndexOf
    A structure variable of type OpcMethodReturnValueInt32. The Result property contains the command-specific return values.
      Result
      The zero-based index position of the first occurrence. If the text is not found, -1 is returned.

Examples:

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

Beckhoff parameter:

    bStringIndexOf
    A boolean variable that can be used to trigger the execution of the IndexOf command.
    OutputDataStringIndexOf
    An instance of the "ST_Int32OutputData" structure into which the return value of the IndexOf method is written.
    hrStringIndexOf
    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.
    StringToSearchIn
    The text to search in.
    StringToSearchInLength
    The length of the string to search in.
    StringToSearchFor
    The string to search for of type "STRING(80)".
    StringToSearchForLength
    The length of the string to search for.
    ConnectionHandle
    "ConnectionHandle" received when establishing a connection between DEPRAG Smart Server and your OPC UA client.


VAR
    bStringIndexOf   : BOOL;
    OutputDataStringIndexOf : ST_Int32OutputData;
    hrStringIndexOf   : HRESULT;

    fbStringOperations : FB_StringOperations;
END_VAR

hrStringIndexOf := fbStringOperations.StringIndexOf(
      bExecute     := bStringConcat, 
      ConnectionHandle  := depragSmartConnection.ConnectionHandle,
      StringToSearchIn  := 'IamATestString',
      StringToSearchInLength := SIZEOF('IamATestString'),
      StringToSearchFor  := 'Test',
      StringToSearchForLength := SIZEOF('Test'), 
      OutputData    => OutputDataStringIndexOf);
IF hrStringIndexOf <> S_FALSE THEN 
      bStringIndexOf := 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".