community postAL Developmentcommunity - not Microsoftreviewed - checked by Opus

Dynamics 365 Business Central: How to check if a string contains particular strings (if a string is a substring of another)

This post explains two methods to check if a string contains a substring in Business Central using AL code: the Text.StrPos method returns the position of the first occurrence, while Text.Contains returns a boolean value. Both approaches are demonstrated with table extension examples.

post Dynamics 365 Lab

Yun Zhu · 2025-11-26 · 327 words · about 1 min

"Text.StrPos(Text, Text) Method: Searches for the first occurrence of substring inside a string."

Key points

  • Text.StrPos returns the position of the first occurrence of a substring, or zero if it is not found
  • StrPos also returns zero when the string or the substring is empty
  • Text.Contains returns a boolean telling whether the substring occurs in the string
  • For case-insensitive checks, convert both strings first with LowerCase or UpperCase
  • Both approaches are shown in a Sales Header table extension using field OnValidate triggers

Quotes

  • “Text.StrPos(Text, Text) Method: Searches for the first occurrence of substring inside a string.” (This is one of two main approaches for finding substrings, showing the foundational method available in AL)
  • “Text.Contains(Text) Method: Returns a value indicating whether a specified substring occurs within this string.” (This is the simpler, more modern alternative method that directly answers the question of substring existence)

AL objects mentioned

As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.

No source states these links: they share an object, a model read them, or a person found the same subject.

Context

  • Features: StrPos method, Contains method, Text comparison, Case-insensitive search

Source: Dynamics 365 Lab - Yun Zhu, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.