StrSearchDelimited Function

Action

Searches for a string delimited on the left by sLeftVal and on the right by sRightVal. The search direction for delimiters can be from left to right and vice versa. It is also possible to search for the n-th occurrence of delimiters. It is further possible to continue a search at the positions found at a previous search.

Include file

Kernel.bdh

Syntax

StrSearchDelimited( out sTarget      : string,
                    in  nMaxTarget   : number,
                    in  sSource      : string,
                    in  sLeftVal     : string allownull,
                    in  nLVOccurrence : number,
                    in  sRightVal    : string allownull,
                    in  nRVOccurrence : number,
                    in  nFlags       : number ): boolean;

Return value

  • true if a substring could be found which is delimited on the left by sLeftVal and on the right by sRightVal and no error occurred

  • false otherwise

Parameter Description
sTarget String variable to receive the found substring
nMaxTarget Maximum number of characters to write into sTarget. This value must be <= the size of sTarget.
sSource Source string to be searched
sLeftVal Left delimiter string to search for
nLVOccurrence Search until sLeftVal is found nLVOccurrence times
sRightVal Right delimiter string to search for
nRVOccurrence Search until sRightVal is found nRVOccurrence times
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_IGNORE_WHITESPACES: Ignore white spaces during search.

注: The STR_SEARCH_NEXT option is allowed only if the function is called with the same source string as in the previous call.
  • A value of zero for nLVOccurrence and nRVOccurrence means that the corresponding position is kept from the previous search.

  • A negative value for nLVOccurrence and nRVOccurrence means to search from right to left.

  • If sLeftVal/sRightVal is null, the beginning/end of the source string is used as a delimiter.

  • Except for the case when nLVOccurrence and nRVOccurrence are negative or the case when nLVOccurrence is positive and nRVOccurrence is negative, the sRightVal is searched starting from the position where sLeftVal is found. If nLVOccurrence and nRVOccurrence are negative, sRightVal is searched first and then the search for sLeftVal starts from the position where sRightVal has been found. If nLVOccurrence is positive and nRVOccurrence is negative, sRightVal is searched starting from the end of the source string.

Example

dcltrans
  transaction TStrSearchDelimited
  var
    sText, sWord1, sWord2, sResult : string;
    nPos                           : number;
    bOk                            : boolean;
  begin
    sText := "The quick brown dog jumps over "
             "the lazy fox and the lazy cat";
    sWord1 := "the";
    sWord2 := "the";
    bOk := StrSearchDelimited(sResult, STRING_COMPLETE, sText,
                              sWord1, 1, sWord2, 1, 0);
    writeln(sResult);

    bOk := StrSearchDelimited(sResult, STRING_COMPLETE, sText,
                              sWord1, 1, sWord2, 2, STR_SEARCH_NEXT);
    writeln(sResult);

    bOk := StrSearchDelimited(sResult, STRING_COMPLETE, sText, 
                              sWord1, 0, sWord2, 1, STR_SEARCH_NEXT);
    writeln(sResult);

    bOk := StrSearchDelimited(sResult, STRING_COMPLETE, sText, sWord1,
                              -1, sWord2, 0, STR_SEARCH_NEXT);
    writeln(sResult);

    bOk := StrSearchDelimited(sResult, STRING_COMPLETE, sText,
                              NULL, 1, sWord2, -1, 0);
    writeln(sResult);

    bOk := StrSearchDelimited(sResult, STRING_COMPLETE, sText,
                              sWord1, 3, NULL, 1, 0);
    writeln(sResult);
  end TStrSearchDelimited;

Output

 quick brown dog jumps over

 quick brown dog jumps over the lazy fox and

The quick brown dog jumps over the lazy fox and
 lazy cat