This documentation is archived and is not being maintained.

String.Chars Property

Updated: August 2010

Gets the character at a specified character position in the current String object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Public ReadOnly Property Chars ( _
	index As Integer _
) As Char
Dim instance As String 
Dim index As Integer 
Dim value As Char 

value = instance.Chars(index)


Type: System.Int32

A character position in the current String object.

Property Value

Type: System.Char
A Unicode character.


index is greater than or equal to the length of this object or less than zero.

The index parameter is zero-based.

This property returns the Char at the position specified by the index parameter. However, a Unicode character might be represented by more than one Char. Use the System.Globalization.StringInfo class to work with each Unicode character instead of each Char.

In C#, the Chars property is an indexer. In Visual Basic, it is the default property of the String class. Each Char object in the string can be accessed by using code such as the following.

Dim str1 As String = "Test" 
For ctr As Integer = 0 to str1.Length - 1
   Console.Write("{0} ", str1(ctr))
' The example displays the following output: 
'      T e s t         

The following example demonstrates how you can use this indexer in a routine to validate a string.

Console.Write("Type a string : ")
Dim myString As String = Console.ReadLine()
Dim i As Integer 
For i = 0 To myString.Length - 1
   If Uri.IsHexDigit(myString.Chars(i)) Then
      Console.WriteLine("{0} is a hexadecimal digit.", myString.Chars(i))
      Console.WriteLine("{0} is not a hexadecimal digit.", myString.Chars(i))
   End If

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0




August 2010

Expanded the Remarks section.

Customer feedback.