FIND_AFTER_POS

Find string's position

FIND_AFTER_POS returns the position at which the second input string IN2 occurs in the first input string IN1 beginning from the start position P. The result is written into the output variable. If the second input string does not occur in the first input string, the value ZERO is returned.

Parameters

Input

IN1 (STRING)

Input string

IN2 (STRING)

Case-sensitive string that is searched for in the input string

P (INT)

Start position of the input string to be searched, where 1 is the first character of the string

Output

Unnamed output (INT)

Position at which the string searched for is found

  • if value > 0: position at which the string searched for is found, whereby 1 refers to the first character

  • if value = 0: search string not found

Remarks

  • If this instruction is used with UTF-8 strings, please refer to the notes concerning UTF-8 strings under the data type STRING.

  • If the strings are longer than the length defined for the input variables (IN1 and IN2) in the declaration field Type, an error occurs (see sys_bIsCarry for error handling).

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)

if a string applied at the input or output is an invalid string

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)

if a string applied at the input or output is an invalid string

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		bStart: BOOL:=FALSE;
		sInputString: STRING[32]:='A better life. A better world.';
		sSearchString: STRING[32]:='A';
		iStartPos: INT:=8;
		iFoundPos: INT:=0;
	END_VAR

In this example the input variables sSearchString and sInputString have been declared. Instead, you may enter the strings directly into the function. The strings have to be put in inverted commas, both in the POU header and in the function.

POU body

sSearchString is searched in sInputString beginning from start position 8. The position of the first occurrence after position 8 is written into iFoundPos.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_F,E_FIND_AFTER_POS!,,19,1,28,7,,?DEN?DIN1?DIN2?DP?AENO?C);
B(B_VARIN,,sInputString,17,3,19,5,);
B(B_VARIN,,sSearchString,17,4,19,6,);
B(B_VARIN,,iStartPos,17,5,19,7,);
B(B_VAROUT,,iFoundPos,28,3,30,5,);
B(B_CONTACT,,bStart,13,2,15,4,);
L(1,3,13,3);
L(15,3,19,3);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF bStart then
    iFoundPos:= FIND_AFTER_POS(sInputString, sSearchString);
END_IF;

IL body

Modified on: 2024-02-26Feedback on this pagePanasonic hotline