本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:String.ToCharArray 输出:
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
开发者ID:VB.NET开发者,项目名称:System,代码行数:11,代码来源:String.ToCharArray 输出:
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
开发者ID:VB.NET开发者,项目名称:System,代码行数:20,代码来源:String.ToCharArray 输出:
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
开发者ID:VB程序员,项目名称:System,代码行数:25,代码来源:String.ToCharArray
注:本文中的System.String.ToCharArray方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论