StrSearch Function

Action

Searches for a substring in a string.

Include file

Kernel.bdh

Syntax

StrSearch(in sSource : string,
          in sSearch : string,
          in nFlags  : number) : number;

Return value

Index of the position of the found substring, or zero if the substring was not found or an error occurred.

Parameter Description
sSource Source string to be searched
sSearch String to search for
nFlags

Option flags. Several combinations of the following options are possible:

  • STR_SEARCH_FIRST: Start a new search.

  • STR_SEARCH_NEXT: Continue a previous search.

  • STR_SEARCH_MATCH_CASE: Search case-sensitive.

  • STR_SEARCH_REVERSE: Search from right to left.

Note: The STR_SEARCH_NEXT option is allowed only if the function is called with the same source string as in the previous call.

Example

dcltrans
  transaction TStrSearch
  var
    sString, sWord : string;
    nPos : number;
  begin
    sString := "The dog, the cat and the mouse are very tired today";
    sWord := "the";
    write("string = "); write(sString); writeln;
    write("word = "); write(sWord); writeln;
    nPos := StrSearch(sString, sWord, STR_SEARCH_FIRST);
    write("pos = "); write(nPos); writeln;
    nPos := StrSearch(sString, sWord, STR_SEARCH_NEXT);
    write("pos = "); write(nPos); writeln;
    nPos := StrSearch(sString, sWord,STR_SEARCH_FIRST | STR_SEARCH_MATCH_CASE);
    write("pos = "); write(nPos); writeln;
    nPos := StrSearch(sString, sWord,STR_SEARCH_FIRST | STR_SEARCH_REVERSE);
    write("pos = "); write(nPos); writeln;
  end TStrSearch;

Output

string = The dog, the cat and the mouse are very tired
today
word = the
pos = 1
pos = 10
pos = 10
pos = 22

Sample scripts

WebFileUpload01.bdf