C# String ToCharArray()

Description

String ToCharArray() copies the characters in this instance to a Unicode character array.

Syntax

String.ToCharArray() has the following syntax.


public char[] ToCharArray()

Returns

String.ToCharArray() method returns

Example

The following example demonstrates how to easily create a Unicode character array from a String.


using System;/*  ww w .java2s. com*/

public class StringSplit2 
{
   public static void Main() 
   {
      string delimStr = " ,.:";
      char[] delimiter = delimStr.ToCharArray();
      for (int x = 1; x <= delimiter.Length; x++) {
         Console.WriteLine(delimiter[x]);
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version