Show: Object Pascal C++
Display Preferences

Locating Items in a String List

From Appmethod Topics
Jump to: navigation, search

Go Up to Manipulating Strings in a 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:

Object Pascal:

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

C++:

if (FileListBox1->Items->IndexOf("WIN.INI") > -1) ...

See Also

Personal tools
In other languages