RAD Studio
ContentsIndex
PreviousUpNext
Locating Items in a String List

To locate a string in a string list, use the IndexOf method. IndexOf returns the index of the first string in the list that matches the parameter passed to it, and returns –1 if the parameter string is not found. IndexOf finds exact matches only; if you want to match partial strings, you must iterate through the string list yourself. 

For example, you could use IndexOf to determine whether a given file name is found among the Items of a list box:

if FileListBox1.Items.IndexOf('TargetFileName') > -1 ...

 

if (FileListBox1->Items->IndexOf("TargetFileName") > -1) ...
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!