Skip to content

IndexText ​

IndexText is a case insensitive function, that determines if any of the strings that are contained in the array AValues match the string specified by AText.

The function returns a zero-based index response where the first match in the array is number zero (0), the second match one (1) etc., and returns minus one (-1) if no match is found.

This function does not take case into account.

Declaration: Function IndexText(const AText : string; const AValues : array of string) : Integer;

Examples follow using a simple array, showing the case sensitivity.

pascal
procedure ScriptEvent(var Value:Variant);
var
  Str1, Str2, Str3 : string;
  Int1, Int2, Int3 : integer;
begin
  Str1 := 'Ken';
  Str2 := 'ken';
  Str3 := 'simone';

  Int1 := IndexText(Str2, ['joe', 'ken', 'fred', 'josh', 'simon']);
  LogInfo(Str2+' is in position # '+IntToStr(Int1));
 If Int1 = -1 then //Matches  ken to ken
   LogInfo('The string is not present.')
 else
    LogInfo('The string is present.');

  Int2 := IndexText(Str1, ['joe', 'ken', 'fred', 'josh', 'simon']);
  LogInfo(Str1+' is in position # '+IntToStr(Int2));
 If Int2 = -1 then //Matches  Ken to ken
   LogInfo('The string is not present.')
 else
    LogInfo('The string is present.');

  Int3 := IndexText(Str3, ['joe', 'ken', 'fred', 'josh', 'simon']);
  LogInfo(Str3+' is in position # '+IntToStr(Int3));
 If Int3 = -1 then //Does not match  simone to any value in the array
   LogInfo('The string is not present.')
 else
    LogInfo('The string is present.');

end;

This code writes to the log as illustrated below.

For a function performing the same role that is case sensitive, please review IndexStr.