search_first

Use the search_first function to search a text for the first occurrence of a fragment. The search can be performed either case-sensitive or case-insensitive.

 search_first ( haystack; needle; casing )

This function returns a value of type NUMBER.

The function has three parameters:

  1. haystack, type TEXT. The text that the search is performed on.
  2. needle, type TEXT. The fragment that is searched for.
  3. casing, type BOOL. When TRUE the search is case-sensitive; otherwise, case-insensitive.

The result of the search function is the offset of the first occurrence of the needle text fragment in the haystack text. If the needle fragment could not be found, the function returns 0.

If the casing parameter is FALSE, a case-insensitive is performed by converting both needle and haystack to lowercase before searching. Applications should account for this conversion in case characters do not have a stable conversion (for example, straße and STRASSE).

Input is always converted to Unicode Normalization Form C (NFC). Tabs, paragraph breaks, and line breaks are handled as characters. Other word processor content, such as layout switches and graphical objects, is stripped before the comparison. Paragraph breaks, and line breaks are considered equal for comparison purposes.

Example

TEXT haystack := "The Quick Brown Fox Jumps Over The Lazy Dog"
TEXT needle := "o"
	 

search_first (haystack; needle; TRUE ) returns 13 (Br'o'wn)

search_first (haystack; needle; FALSE) returns 27 ('O'ver)

search_first (needle; haystack; TRUE ) returns 0