本文整理匯總了VB.NET中System.String.ToCharArray方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET String.ToCharArray方法的具體用法?VB.NET String.ToCharArray怎麽用?VB.NET String.ToCharArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.String
的用法示例。
在下文中一共展示了String.ToCharArray方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Sample
' Sample for String.ToCharArray(Int32, Int32)
Class Sample
Public Shared Sub Main()
Dim str As String = "012wxyz789"
Dim arr() As Char
arr = str.ToCharArray(3, 4)
Console.Write("The letters in '{0}' are: '", str)
Console.Write(arr)
Console.WriteLine("'")
Console.WriteLine("Each letter in '{0}' is:", str)
Dim c As Char
For Each c In arr
Console.WriteLine(c)
Next c
End Sub
End Class
輸出:
The letters in '012wxyz789' are: 'wxyz' Each letter in '012wxyz789' is: w x y z
示例2: Example
Module Example
Public Sub Main()
Dim s As String = "AaBbCcDd"
Dim chars() = s.ToCharArray()
Console.WriteLine("Original string: {0}", s)
Console.WriteLine("Character array:")
For ctr = 0 to chars.Length - 1
Console.WriteLine(" {0}: {1}", ctr, chars(ctr))
Next
End Sub
End Module
輸出:
Original string: AaBbCcDd Character array: 0: A 1: a 2: B 3: b 4: C 5: c 6: D 7: d
示例3: StringSplit2
Public Class StringSplit2
Public Shared Sub Main()
Dim delimStr As String = " ,.:"
Dim delimiter As Char() = delimStr.ToCharArray()
Dim words As String = "one two,three:four."
Dim split As String() = Nothing
Console.WriteLine("The delimiters are -{0}-", delimStr)
Dim x As Integer
For x = 1 To 5
split = words.Split(delimiter, x)
Console.WriteLine(ControlChars.Cr + "count = {0,2} ..............", x)
Dim s As String
For Each s In split
Console.WriteLine("-{0}-", s)
Next s
Next x
End Sub
End Class
輸出:
The delimiters are - ,.:- count = 1 .............. -one two,three:four.- count = 2 .............. -one- -two,three:four.- count = 3 .............. -one- -two- -three:four.- count = 4 .............. -one- -two- -three- -four.- count = 5 .............. -one- -two- -three- -four- --
示例4: String.ToCharArray()
' 導入命名空間
Imports System
Public Class MainClass
Shared Sub Main()
Dim string1 As String = "hello"
Dim string2 As String = "GOOD BYE "
Dim string3 As String = " spaces "
Dim i As Integer
Dim charArray() As Char = string1.ToCharArray()
Console.WriteLine("string1 = " & string1 & vbCrLf & "string2 = " & _
string2 & vbCrLf & "string3 = " & string3)
For i = 0 To charArray.Length - 1
Console.WriteLine(charArray(i))
Next
End Sub ' Main
End Class