delphifindcomparetstringlist

Delphi: TStringList.Contains?


Is there any integrated solution in Delphi 2007 to check whether a TStringList contains a part of a certain value?

e.g.:

List.AddObject('This is a string', customStringObject1); 
List.AddObject('This is a mushroom', customStringObject2); 
List.AddObject('Random stuff', customStringObject3); 

Searching for "This is a" is supposed to deliver me "true", since the first two elements contain this partwise.

The only method i'm aware of so far is TStringList.find(string,integer), but this performs a complete string comparision, i.e. only searching for This is a string will return true.

Any suggestions?


Solution

  • Not integrated, but you can use the Pos function on the Text property:

    Pos('This is a', List.Text)
    

    And if you want it to be integrated, you can create a class helper for TStrings.