You can use the String.IndexOf method to return the index where a particular character is encountered, as in the following example:
Dim myString As String = "ABCDE"
Dim myInteger As Integer
myInteger = myString.IndexOf("D") ' myInteger = 3
In the previous example, the IndexOf method of myString was used to return the index corresponding to the first instance of the character "C" in the string. IndexOf is an overloaded method, and the other overloads provide methods to search for any of a set of characters, or to search for a string within your string, among others. The Visual Basic .NET command InStr also allows you to perform similar functions. For more information of these methods, see String.IndexOf Method and InStr Function. You can also use the String.LastIndexOf Method to search for the last occurrence of a character in your string.
|