{"title":"Text.StrPos(Text, Text) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/text/text-strpos-method/","by":"JOP-AL","license":"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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/text/text-strpos-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Searches for the first occurrence of substring inside a string.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":124,"chars":152},{"level":2,"title":"Parameters","slug":"parameters","at":276,"chars":157},{"level":2,"title":"Return Value","slug":"return-value","at":433,"chars":140},{"level":2,"title":"Remarks","slug":"remarks","at":573,"chars":215},{"level":2,"title":"Example 1","slug":"example-1","at":788,"chars":714},{"level":2,"title":"Example 2","slug":"example-2","at":1502,"chars":187},{"level":2,"title":"Related information","slug":"related-information","at":1689,"chars":132}],"text":"> Version: _Available or changed with runtime version 1.0._\nSearches for the first occurrence of substring inside a string.\n## Syntax\n```al\nPosition :=   Text.StrPos(String: Text, SubString: Text)\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nString\nType: text-data-type\nThe string in which you want to search.\nSubString\nType: text-data-type\nThe substring for which you want to search.\n## Return Value\nPosition\nType: ../integer/integer-data-type\nThe one-based index of the first occurrence of the substring inside the string.\n## Remarks\nThe StrPos method returns the position of the first occurrence of the substring.\nIf SubString cannot be found, then the method returns zero.\nIf String or SubString is empty, then the method returns zero.\n## Example 1\nThis example shows how to use the StrPos method.\n```al\nvar\n    Text000: Label 'ABC abc abc xy';\n    Text001: Label 'abc';\n    Text002: Label 'The search for the substring: >%1<\\\\';\n    Text003: Label 'in the string: >%2<,\\\\';\n    Text004: Label 'returns the position: %3';\nbegin\n    String := Text000;\n    SubStr := Text001\n    Pos := StrPos(String, SubStr);\n    Message(Text002 + Text003 + Text004, SubStr, String, Pos);\n    // The StrPos method is case-sensitive. Furthermore, it only\n    // returns the position of the 1st occurrence of the substring.\nend;\n```\nThe message window displays the following:\nThe search for the substring: >abc\\<\nin the string: >ABC abc abc xy\\<\nreturns the position: 5\n## Example 2\n```al\nPos1 := StrPos(\"abc\",\"\"); // Returns 0.\nPos2 := StrPos(\"abc\",\"c\"); // Returns 3.\nPos3 := StrPos(\"abc\",\"bc\"); // Returns 2.\nPos4 := StrPos(\"abc\",\"x\"); // Returns 0.\n```\n## Related information\ntext-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}