System.Classes.TStrings.IndexOf

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function IndexOf(const S: string): Integer; virtual;

C++

virtual int __fastcall IndexOf(const System::UnicodeString S);

Properties

Type Visibility Source Unit Parent
function public
System.Classes.pas
System.Classes.hpp
System.Classes TStrings

Description

Returns the position of a string in the list.

Call IndexOf to obtain the position of the first occurrence of the S string. IndexOf is not case-sensitive; this means that the given string may differ in case from the string in the list. For example:

String1 := MyStrings.Items.IndexOf('My First String');

is equivalent to

String1 := MyStrings.Items.IndexOf('My FIRST String');

IndexOf returns the 0-based index of the string. Thus, if S matches the first string in the list, IndexOf returns 0, if S is the second string, IndexOf returns 1, and so on. If the string is not in the string list, IndexOf returns -1.

Note: If the string appears in the list more than once, IndexOf returns the position of the first occurrence.

See Also

Code Examples