StringIx

Declaration: StringIx (InString: string; CaseSensitive: boolean; SArray: TStrArray): integer;

The function StringIx tries to match the string InString against the strings of the array SArray. If InString is found in SArray StringIx returns the index of the matched entry (the elements of the array are numbered with indices starting at 1). If no match has been found a zero value is returned. The parameter CaseSensitive allows to control whether the function is case-sensitive.

Example: The function StringIx can be used in case statements for the comparison of strings (thus avoiding cascading if-then-else statements). The following code shows how to evaluate the input of an edit control:
case StringIx (Edit1.Text, ['cmd1', 'cmd2', 'cmd3']) of
  1 : begin
      // process command 1 here
      end;
  2 : begin
      // process command 2 here
      end;
  3 : begin
      // process command 3 here
      end;
 else begin
      // process unknown command
      end;
end;


Last Update: 2020-Apr-18