How to: Access Characters in Strings in Visual Basic
This example demonstrates how to use theproperty to access the character at the specified location in a string.
Sometimes it is useful to have data about the characters in your string and the positions of those characters within your string. You can think of a string as an array of characters (Char instances); you can retrieve a particular character by referencing the index of that character through the Chars property.
Dim myString As String = "ABCDE" Dim myChar As Char ' Assign "D" to myChar. myChar = myString.Chars(3)
The index parameter of the Chars property is zero-based.
The Chars property returns the character at the specified position. However, some Unicode characters can be represented by more than one character. For more information on how to work with Unicode characters, see.
The Chars property throws an index parameter is greater than or equal to the length of the string, or if it is less than zeroexception if the