strFind (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 (4.60 : for the 'start' parameter) / 1.00.00


strFind will search for a string within another string. It will return the start position of "str2" in "str1" if str2 was found in str1 - otherwise it will return 0. It is possible to search for the string without case sensitivity - that is to say that "abc" will be the same as "ABC" if no case checking is done (see input parameter CheckCase).

 

Please note that if either str1 or str2 is empty, this function will return 0 (not found).

 

Input:

str1 : STRING

String to search in.

 

str2 : STRING

String to search for.

 

start : int Default:1

Position in "str1" where the search for "str2" starts.
Default is to start at the beginning of 'str1' which equals 'start=1'.

 

CheckCase : BOOL Default: FALSE

TRUE if the search should be case-sensitive.

 

Returns: INT

The start position of "str2" in "str1", 0 if "str2" was not found.
The first character of "str1" is defined as position 1.

 

Declaration:

FUNCTION strFind : INT;
VAR_INPUT
  str1     : STRING;
  str2     : STRING;
  start     : INT := 1;
  CheckCase : BOOL := FALSE;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  result : INT;
END_VAR;
 
PROGRAM test;
 
BEGIN
  ...
result := strFind(str1:="hello world", str2:="World");
  // result will contain 7 after the call
result := strFind(str1:="Hard and harder", str2:="hard", start:=5);
  // result will contain 10 after the call
  ...
END;
 
END_PROGRAM;