| Unit: | SDL_stringl |
| Class: |
none |
| Declaration: |
function StringIx (InString: string; SArray: array of string): integer; {Pascal}
int __fastcall StringIx(AnsiString InString, const AnsiString * 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.
| 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):
int __fastcall StringIx(AnsiString InString, const AnsiString * SArray, const int SArray_Size); |
| 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;
|
|