{"title":"Text.SelectStr(Integer, Text) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/text/text-selectstr-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-selectstr-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-selectstr-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":"Retrieves a substring from a comma-separated string.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Text.SelectStr(Integer, Text) Method","slug":"textselectstrinteger-text-method","at":0,"chars":2352},{"level":2,"title":"Syntax","slug":"syntax","at":152,"chars":161},{"level":2,"title":"Parameters","slug":"parameters","at":313,"chars":403},{"level":2,"title":"Return Value","slug":"return-value","at":716,"chars":117},{"level":2,"title":"Remarks","slug":"remarks","at":833,"chars":325},{"level":2,"title":"Example 1","slug":"example-1","at":1158,"chars":811},{"level":2,"title":"Example 2","slug":"example-2","at":1969,"chars":251},{"level":2,"title":"Related information","slug":"related-information","at":2220,"chars":132}],"text":"# Text.SelectStr(Integer, Text) Method\n> Version: _Available or changed with runtime version 1.0._\nRetrieves a substring from a comma-separated string.\n## Syntax\n```al\nNewString :=   Text.SelectStr(Number: Integer, CommaString: Text)\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nNumber\nType: ../integer/integer-data-type\nSpecifies which substring to retrieve. The substrings in the comma-separated string are numbered 1, 2, 3, and so on. If Number is greater than the actual number of substrings, then a run-time error occurs.\nCommaString\nType: text-data-type\nA string that contains substrings separated by commas. The maximum length of this string is 391 characters.\n## Return Value\nNewString\nType: text-data-type\nThe substring from the comma-separated string at the index specified.\n## Remarks\nAny trailing commas are removed before the operation starts.\nIf Number is less than 1 or greater than the number of real values \\(excluding trailing commas\\) in the string, then an error is returned.\nQuotes aren't supported. For example, a,b,\"c,d\",e is treated as a five-element substring where substring 4 is d\".\n## Example 1\n```al\nvar\n    CommaStr: Text[60];\n    CommaStr2: Text[60];\n    SubStr1: Text[60];\n    SubStr2: Text[60];\n    SubStr3: Text[60];\n    SubStr4: Text[60];\n    Text000: Label 'This,is a comma,separated,string';\n    Text001: Label 'The calls to SelectStr return:\\\\';\n    Text002: Label '11,22,33,,55,,,';\nbegin\n    CommaStr := Text000;\n    CommaStr2 := Text002;\n    SubStr1 := SelectStr(2, CommaStr); // Pick out the 2nd substring.\n    SubStr2 := SelectStr(4, CommaStr); // Pick out the 4th substring.\n    SubStr3 := SelectStr(1, CommaStr2);\n    SubStr4 := SelectStr(3, CommaStr2);\n    Message(Text001 + '>%1<\\' + '>%2<\\' + '>%3<\\' + '>%4<\\', SubStr1, SubStr2, SubStr3, SubStr4);\nend;\n```\nThe message window displays the following text:\nThe calls to SelectStr return:\n>is a comma\\<\n>string\\<\n>11\\<\n>33\\<\n## Example 2\n```al\nvar\n    CommaStr2: Text[60];\n    SubStr5: Text[60];\n    Text002: Label '11,22,33,,55,,,';\nbegin\n    CommaStr2 := Text002;\n    SubStr5 := SelectStr(6,CommaStr2);\n    Message('>%1<\\', SubStr5);\nend;\n```\nThis example returns an error.\n## Related information\ntext-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}