The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



TStringSearch


The class TStringSearch allows to search for partial strings, using boolean expressions. The string to be searched has to be assigned to the property InString, the search expression is specified by the property SearchExpression. The method DoSearch returns TRUE if the search expression matches the string assigned to InString. In this case the properties NumFoundItems, FoundItemsPos and FoundItemsLength contain the number of found matches, and the positions and the lengths of the found matches.

The search expression can be any combination of strings and the boolean operators AND, OR and NOT. The AND operator is indicated by the plus sign ('+'), the OR operator by the comma (','), and the NOT operator by the tilde ('~'). Further, expressions may contain parantheses to control the operator precendence. The sub-strings to be searched for must consist of characters (A-Z, a-z, umlauts) or numbers. The characters '+,~()' cannot be searched for since they are interpreted as operators.

The property IgnoreCase controls the case sensitivity of the search.

Example: Assume the search expression is set to "(wine,water)+analysis": Then the DoSearch method returns TRUE if the string InString contains either "wine" and "analysis", or "water" and "analysis", or "wine", "water" and "analysis".

Following is a code torso showing how to use TStringSearch:(1)

var
  StrSrc : TStringSearch;
  i      : integer;

begin
...
StrSrc := TStringSearch.Create(nil);
StrSrc.InString := ...  // assign the string to be searched
StrSrc.SearchExpression := '(wine,water)+analysis';
if StrSrc.DoSearch then
  begin
  for i:=1 to StrSrc.NumFoundItems do
    begin
      ... // process the found matches
    end;
  end;
StrSrc.Free;
...
end;
(1) As an alternative, you could put a TStringSearch icon on the form; in this case the variable declaration, and the Create and Free statements have to be omitted.



Last Update: 2012-Oct-20