Searches for the first occurrence of substring inside a string.

Position := STRPOS(String, SubString)



Type: Text constant or codeThe string in which you want to search.

Type: Text constant or codeThe substring for which you want to search.The STRPOS function is case-sensitive.

Property Value/Return Value

Type: Integer

The position of SubString in String.


The STRPOS function returns the position of the first occurrence of the substring.

If SubString cannot be found, then the function returns zero.

If String or SubString is empty, then the function returns zero.


This example shows how to use the STRPOS function.

This example requires that you create the following text constants in the C/AL Globals window.

Text constant ENU value


'ABC abc abc xy'




'The search for the substring: >%1<\'


'in the string: >%2<,\'


'returns the position: %3'

  Copy Code
String := Text000;
SubStr := Text001
Pos := STRPOS(String, SubStr);
MESSAGE(Text002 + Text003 + Text004, SubStr, String, Pos);
// The STRPOS function is case-sensitive. Furthermore, it only
// returns the position of the 1st occurrence of the substring.

The message window displays the following:

The search for the substring: >abc<

in the string: >ABC abc abc xy<

returns the position: 5

  Copy Code
Pos1 := StrPos("abc",""); // Returns 0.
Pos2 := StrPos("abc","c"); // Returns 3.
Pos3 := StrPos("abc","bc"); // Returns 2.
Pos4 := StrPos("abc","x"); // Returns 0.

See Also