# Text.StrPos(Text, Text) Method
> Version: _Available or changed with runtime version 1.0._
Searches for the first occurrence of substring inside a string.
## Syntax
```al
Position :=   Text.StrPos(String: Text, SubString: Text)
```
> NOTE
> This method can be invoked without specifying the data type name.
## Parameters
String
Type: text-data-type
The string in which you want to search.
SubString
Type: text-data-type
The substring for which you want to search.
## Return Value
Position
Type: ../integer/integer-data-type
The one-based index of the first occurrence of the substring inside the string.
## Remarks
The StrPos method returns the position of the first occurrence of the substring.
If SubString cannot be found, then the method returns zero.
If String or SubString is empty, then the method returns zero.
## Example 1
This example shows how to use the StrPos method.
```al
var
    Text000: Label 'ABC abc abc xy';
    Text001: Label 'abc';
    Text002: Label 'The search for the substring: >%1<\\';
    Text003: Label 'in the string: >%2<,\\';
    Text004: Label 'returns the position: %3';
begin
    String := Text000;
    SubStr := Text001
    Pos := StrPos(String, SubStr);
    Message(Text002 + Text003 + Text004, SubStr, String, Pos);
    // The StrPos method is case-sensitive. Furthermore, it only
    // returns the position of the 1st occurrence of the substring.
end;
```
The message window displays the following:
The search for the substring: >abc\<
in the string: >ABC abc abc xy\<
returns the position: 5
## Example 2
```al
Pos1 := StrPos("abc",""); // Returns 0.
Pos2 := StrPos("abc","c"); // Returns 3.
Pos3 := StrPos("abc","bc"); // Returns 2.
Pos4 := StrPos("abc","x"); // Returns 0.
```
## Related information
text-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/text/text-strpos-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/text/text-strpos-method/
