RAD Studio |  |

Locating Items in a String List
See Also
Collapse All

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:

Copy Code

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

Copy Code

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

See Also

Manipulating Strings in a List

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!