search

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

 search ( haystack; needle; start; sensitive )

This function returns a value of type NUMBER.

The function has four parameters:

  1. haystack, type TEXT. The text that the search is performed on.
  2. needle, type TEXT. The fragment that is searched for.
  3. start, type NUMBER. The offset in the haystack text where the search should start. Use a value of 1 to start at the first character of haystack.
  4. sensitive, 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 at or past the start offset. If the needle fragment could not be found, the function returns 0.

If the sensitive 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 (haystack; needle; 1; TRUE ) returns 13 (Brown)

search (haystack; needle; 20; TRUE ) returns 42 (Dog)

search (haystack; needle; 20; FALSE) returns 27 (Over)

search (needle; haystack; 1; TRUE ) returns 0