本文整理匯總了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