TStringList.IndexOf: template in index?

I want to get linenumber in a string list (loaded from a file). Indexof seems to match exactly. Is there a way to get a string with a wildcard version of Indexof? something like SL.Indexof ('? sometext')?

Thanks!

+6
source share
2 answers

If you want to match some part of the string without any fancy wildcards, as you point out in the comment to another answer, you can use a simple function, for example:

function FindMatchStr(Strings: TStrings; const SubStr: string): Integer; begin for Result := 0 to Strings.Count-1 do if ContainsStr(Strings[Result], SubStr) then exit; Result := -1; end; 

If you want case insensitive, you can use this:

 function FindMatchText(Strings: TStrings; const SubStr: string): Integer; begin for Result := 0 to Strings.Count-1 do if ContainsText(Strings[Result], SubStr) then exit; Result := -1; end; 

ContainsStr and ContainsText defined in the StrUtils RTL StrUtils and follow the standard Str conventions to indicate case-sensitive comparisons and Text to indicate case-insensitivity.

+9
source

There is no built-in way to find a TStringList for wildcards. For regular expressions, you need to use a third-party library such as TPerlRegEx .

+7
source

Source: https://habr.com/ru/post/890486/


All Articles