IndexOf
function IndexOf(const S: string): Integer;
Example
procedure FindStatus(const Items: TStringList; var FoundAt: Integer);
begin
FoundAt := Items.IndexOf('Complete');
end;
Usage
IndexOf returns the first matching string index under the list's comparison policy, or minus one.
- Test for
>= 0;-1means no match. - Do not compare the result with
Countas a not-found sentinel. - Locale and case settings can make results environment-sensitive.
Additional Technical Info
IndexOf is declared by hidden ancestor TStrings and is normally used through a concrete visible descendant such as TStringList. Matching can therefore differ from the exact comparison used by Equals.
Source-backed behaviour
The base implementation scans from index zero and calls virtual CompareStrings until it returns zero. A TStringList override uses a linear scan when unsorted and binary Find when sorted.
For TStringList, CaseSensitive and UseLocale influence comparison. The current script constructor defaults to case-insensitive, locale-aware comparison. A sorted list returns a matching position according to the binary-search path; when accepted duplicates exist, callers must not assume which equal entry is returned.
Related members
IndexOfName searches name/value keys and IndexOfObject uses object identity. Equals always performs ordered case-sensitive text equality.