Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String::Chars Property

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

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

public:
property wchar_t Chars[int index] {
	wchar_t get (int index);
}

Parameters

index
Type: System::Int32

A position in the current string.

Property Value

Type: System::Char
The object at position index.

ExceptionCondition
IndexOutOfRangeException

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 object 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 Unicode characters instead of Char objects. For more information, see the "Char Objects and Unicode Characters" section in the String class overview.

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.

No code example is currently available or this language may not be supported.

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

Console::Write( "Type a string : " );
String^ myString = Console::ReadLine();
for ( int i = 0; i < myString->Length; i++ )
   if ( Uri::IsHexDigit( myString[ i ] ) )
            Console::WriteLine( "{0} is a hexadecimal digit.", myString[ i ] );
   else
            Console::WriteLine( "{0} is not a hexadecimal digit.", myString[ i ] );
// The example produces output like the following: 
//    Type a string : 3f5EaZ 
//    3 is a hexadecimal digit. 
//    f is a hexadecimal digit. 
//    5 is a hexadecimal digit. 
//    E is a hexadecimal digit. 
//    a is a hexadecimal digit. 
//    Z is not a hexadecimal digit.      

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft