FIND

Searches for a substring within a string.

Signature

     ┌─────────┐
IN1 ─┤         │
     │  FIND   ├─ OUT
IN2 ─┤         │
     └─────────┘
FUNCTION FIND : ANY_INT
  VAR_INPUT
    IN1 : ANY_STRING;
    IN2 : ANY_STRING;
  END_VAR
END_FUNCTION

Returns INT. FIND accepts STRING for IN1 and IN2. Both inputs must share the same type.

Inputs

Name

Type

Description

IN1

ANY_STRING

The string to search within.

IN2

ANY_STRING

The substring to find.

Outputs

Name

Type

Description

Return value

INT

1-based position of the first occurrence of IN2 in IN1, or 0 if not found.

Description

FIND(IN1, IN2) returns the position of the first occurrence of IN2 within IN1. Positions are 1-based. If IN2 is not found, the function returns 0.

Example

result := FIND('Hello World', 'World');   (* result = 7 *)
result := FIND('Hello World', 'xyz');     (* result = 0 *)
result := FIND('ABCABC', 'BC');           (* result = 2 *)

See Also

  • REPLACE — string replacement

  • MID — middle substring

  • LEN — string length

References