本文整理汇总了VB.NET中System.Text.StringBuilder.Replace方法的典型用法代码示例。如果您正苦于以下问题:VB.NET StringBuilder.Replace方法的具体用法?VB.NET StringBuilder.Replace怎么用?VB.NET StringBuilder.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.Replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Sample
' 导入命名空间
Imports System.Text
Class Sample
Public Shared Sub Main()
' 0----+----1----+----2----+----3----+----4---
' 01234567890123456789012345678901234567890123
Dim str As String = "The quick br!wn d#g jumps #ver the lazy cat."
Dim sb As New StringBuilder(str)
Console.WriteLine()
Console.WriteLine("StringBuilder.Replace method")
Console.WriteLine()
Console.WriteLine("Original value:")
Show(sb)
sb.Replace("#"c, "!"c, 15, 29) ' Some '#' -> '!'
Show(sb)
sb.Replace("!"c, "o"c) ' All '!' -> 'o'
Show(sb)
sb.Replace("cat", "dog") ' All "cat" -> "dog"
Show(sb)
sb.Replace("dog", "fox", 15, 20) ' Some "dog" -> "fox"
Console.WriteLine("Final value:")
Show(sb)
End Sub
Public Shared Sub Show(sbs As StringBuilder)
Dim rule1 As String = "0----+----1----+----2----+----3----+----4---"
Dim rule2 As String = "01234567890123456789012345678901234567890123"
Console.WriteLine(rule1)
Console.WriteLine(rule2)
Console.WriteLine("{0}", sbs.ToString())
Console.WriteLine()
End Sub
End Class
输出:
StringBuilder.Replace method Original value: 0----+----1----+----2----+----3----+----4--- 01234567890123456789012345678901234567890123 The quick br!wn d#g jumps #ver the lazy cat. 0----+----1----+----2----+----3----+----4--- 01234567890123456789012345678901234567890123 The quick br!wn d!g jumps !ver the lazy cat. 0----+----1----+----2----+----3----+----4--- 01234567890123456789012345678901234567890123 The quick brown dog jumps over the lazy cat. 0----+----1----+----2----+----3----+----4--- 01234567890123456789012345678901234567890123 The quick brown dog jumps over the lazy dog. Final value: 0----+----1----+----2----+----3----+----4--- 01234567890123456789012345678901234567890123 The quick brown fox jumps over the lazy dog.
示例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