16.6. Locating Characters and Substrings in Strings

In many applications, it is necessary to search for a character or set of characters in a String. For example, a programmer creating a word processor would want to provide capabilities for searching through documents. Figure 16.5 demonstrates some of the many versions of String methods IndexOf, IndexOfAny, LastIndexOf and LastIndexOfAny, which search for a specified character or substring in a String. This example searches the String letters which is initialized with "abcdefghijklmabcdefghijklm" (line 6).

Figure 16.5. Searching for characters and substrings in Strings.
					1
					' Fig. 16.5: StringIndexMethods.vb
					2
					' Using String searching methods.
					3
					4
					Module StringIndexMethods
 5
					Sub Main()
 6
					Dim ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.