Export (0) Print
Expand All
2 out of 10 rated this helpful - Rate this topic

String.Chars Property

Gets the character at a specified character position in this instance.

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

public char this [
	int index
] { get; }
/** @property */
public char get_Chars (int index)

JScript supports the use of indexed properties, but not the declaration of new ones.

Parameters

index

A character position in this instance.

Property Value

A Unicode character.
Exception typeCondition

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 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.

The following code 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]); 

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.