The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....


Class: none
Declaration: [1] function StringIx (InString: string; SArray: array of string): integer; {Pascal}
int __fastcall StringIx(System::UnicodeString InString, System::UnicodeString *SArray, const int SArray_Size); {C++}
[2] function StringIx (InString: string; CaseSensitive: boolean; SArray: array of string): integer; {Pascal}
int int __fastcall StringIx(System::UnicodeString InString, bool CaseSensitive, System::UnicodeString *SArray, const int SArray_Size); {C++}

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.

Version [1] is always case-sensitive, while version [2] offers the parameter CaseSensitive to control whether the function is case-sensitive.

Hint: The declaration of StringIx in C++ slightly differs from the Pascal declaration (note the extra parameter SArray_Size which specifies the highest index of the SArray array).

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
  2 : begin
      // process command 2 here
  3 : begin
      // process command 3 here
 else begin
      // process unknown command

Last Update: 2014-Apr-17