Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

String.ToCharArray Method

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
<SecuritySafeCriticalAttribute> _
Public Function ToCharArray As Char()

Return Value

Type: System.Char()
A Unicode character array whose elements are the individual characters of this instance. If this instance is an empty string, the returned array is empty and has a zero length.

The following code example demonstrates how to easily create a Unicode character array from a String. The array is then used with the Split method.

Public Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim delimStr As String = " ,.:"
      Dim delimiter() As Char = delimStr.ToCharArray()
      Dim words As String = "one two,three:four."
      Dim split() As String = Nothing

      outputBlock.Text &= "The delimiters are:" & vbCrLf
      For Each ch As Char In delimStr
         outputBlock.Text &= String.Format("   '{0}'", ch) + vbCrLf
      outputBlock.Text &= vbCrLf

      split = words.Split(delimiter)
      For Each s As String In split
         outputBlock.Text += String.Format("'{0}'", s) & vbCrLf
   End Sub 
End Class 
' The example displays the following output:
'       The delimiters are:
'          ''
'          ','
'          '.'
'          ':'
'       'one'
'       'two'
'       'three'
'       'four'
'       ''    


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.