This topic has not yet been rated - Rate this topic

String.ToCharArray Method (Int32, Int32)

April 12, 2014

Copies the characters in a specified substring in this instance to a Unicode character array.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public char[] ToCharArray(
	int startIndex,
	int length
)

Parameters

startIndex
Type: System.Int32
The starting position of a substring in this instance.
length
Type: System.Int32
The length of the substring in this instance.

Return Value

Type: System.Char []
A Unicode character array whose elements are the length number of characters in this instance starting from character position startIndex.
ExceptionCondition
ArgumentOutOfRangeException

startIndex or length is less than zero.

-or-

startIndex plus length is greater than the length of this instance.

The startIndex parameter is zero-based. That is, the index of the first character in the string instance is zero.

If length is zero, the returned array is empty and has a zero length. If this instance is null or an empty string (""), the returned array is empty and has a zero length.

The following example converts a substring within a string to an array of characters, and then enumerates and displays the elements of the array.

Windows Phone OS

Supported in: 8.1, 8.0

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.