AnsiIndexStr
Belongs to : FunctionDescription
The AnsiIndexStr function checks to see if any of the strings in StringList exactly match the Source string.
When a match is found, its (0 based) index is returned. Otherwise, -1 is returned.
The string list can be specified as a square bracket delimited list, as in the example, or as an array of strings.
It is a Case sensitive command.
Example code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
var source : AnsiString; position : Integer; begin source := 'Henry'; // The string to match // Note that AnsiIndexStr is case sensitive // We use a hard coded constant string array position := AnsiIndexStr(source, ['BRIAN', 'JIM', 'HENRY']); ShowMessageFmt('Index of first match attempt = %d',[position]); // Note that arrays start at 0 position := AnsiIndexStr(source, ['Brian', 'Jim', 'Henry']); ShowMessageFmt('Index of second match attempt = %d',[position]); end; Show full unit code Index of first match attempt = -1 Index of second match attempt = 2 |