C# String ToCharArray(Int32, Int32)
Description
String ToCharArray(Int32, Int32)
copies the characters
in a specified substring in this instance to a Unicode character array.
Syntax
String.ToCharArray(Int32, Int32)
has the following syntax.
public char[] ToCharArray(
int startIndex,
int length
)
Parameters
String.ToCharArray(Int32, Int32)
has the following parameters.
startIndex
- The starting position of a substring in this instance.length
- The length of the substring in this instance.
Returns
String.ToCharArray(Int32, Int32)
method returns
Example
The following example converts a substring within a string to an array of characters, then enumerates and displays the elements of the array.
using System;//www .java2 s .co m
class Sample {
public static void Main() {
string str = "this is a test";
char[] arr;
arr = str.ToCharArray(3, 4);
foreach (char c in arr)
Console.WriteLine(c);
}
}
The code above generates the following result.