本文整理汇总了VB.NET中System.Text.StringBuilder.Chars属性的典型用法代码示例。如果您正苦于以下问题:VB.NET StringBuilder.Chars属性的具体用法?VB.NET StringBuilder.Chars怎么用?VB.NET StringBuilder.Chars使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Text.StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.Chars属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Text
Module Example
Public Sub Main()
Dim nAlphabeticChars As Integer = 0
Dim nWhitespace As Integer = 0
Dim nPunctuation As Integer = 0
Dim sb As New StringBuilder("This is a simple sentence.")
For ctr As Integer = 0 To sb.Length - 1
Dim ch As Char = sb(ctr)
If Char.IsLetter(ch) Then nAlphabeticChars += 1 : Continue For
If Char.IsWhiteSpace(ch) Then nWhitespace += 1 : Continue For
If Char.IsPunctuation(ch) Then nPunctuation += 1
Next
Console.WriteLine("The sentence '{0}' has:", sb)
Console.WriteLine(" Alphabetic characters: {0}", nAlphabeticChars)
Console.WriteLine(" White-space characters: {0}", nWhitespace)
Console.WriteLine(" Punctuation characters: {0}", nPunctuation)
End Sub
End Module
输出:
The sentence 'This is a simple sentence.' has: Alphabetic characters: 21 White-space characters: 4 Punctuation characters: 1
示例2: Module1
' 导入命名空间
Imports System.Text
Module Module1
Sub Main()
Dim SB As StringBuilder = New StringBuilder(26)
SB.Append("ABCDEFGHIJKLMNOPQRSTUVWYZ")
SB.Chars(4) = "e"
SB.Chars(0) = "a"
SB.Replace("aBCDe", "ABCDE")
Console.WriteLine("Ending StringBuilder: " & SB.ToString())
End Sub
End Module