Mega Code Archive

 
Categories / Delphi / Functions
 

Ansiindexstr - compares a string with a list of strings - returns match strutils unit

function AnsiIndexStr ( const Source : string; const StringList : array of string ) : Integer; Description 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. Related commands AnsiMatchStr Returns true if a string exactly matches one of a list of strings AnsiPos Find the position of one string in another Example code : A simple example 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