Demonstrating methods Insert and Remove of the StringBuilder class : StringBuilder « Data Type « VB.Net Tutorial






Imports System.Text
Imports System.Windows.Forms

Module Tester

   Sub Main()
      Dim objectValue As Object = "hello"
      Dim stringValue As String = "good bye"
      Dim characterArray As Char() = {"a"c, "b"c, "c"c, "d"c, "e"c, "f"c}

      Dim booleanValue As Boolean = True
      Dim characterValue As Char = "K"c
      Dim integerValue As Integer = 7
      Dim longValue As Long = 12345677890
      Dim singleValue As Single = 2.5
      Dim doubleValue As Double = 33.333
      Dim buffer As StringBuilder = New StringBuilder()
      Dim output As String

      ' insert values into buffer
      buffer.Insert(0, objectValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, stringValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, characterArray)
      buffer.Insert(0, "  ")
      buffer.Insert(0, booleanValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, characterValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, integerValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, longValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, singleValue)
      buffer.Insert(0, "  ")
      buffer.Insert(0, doubleValue)
      buffer.Insert(0, "  ")

      output = "buffer after inserts:" & vbCrLf & _
         buffer.ToString() & vbCrLf & vbCrLf

      buffer.Remove(12, 1) ' delete 5 in 2.5
      buffer.Remove(2, 4) ' delete 33.3 in 33.333

      output &= "buffer after Removes:" & vbCrLf & _
         buffer.ToString()

      Console.WriteLine(output)
   End Sub ' Main 

End Module
buffer after inserts:
  33.333  2.5  12345677890  7  K  True  abcdef  good bye  hello

buffer after Removes:
  33  2.  12345677890  7  K  True  abcdef  good bye  hello








2.40.StringBuilder
2.40.1.Demonstrating StringBuilder class constructors
2.40.2.StringBuilder: Insert string, Append and Replace
2.40.3.Append Char to StringBuilder
2.40.4.Demonstrating StringBuilder Append methods
2.40.5.StringBuilder AppendFormat
2.40.6.StringBuilder.AppendFormat: {0:D} is ${1: #,###.00}
2.40.7.Replace method.
2.40.8.Insert method of StringBuilder
2.40.9.StringBuilder: Length, Capacity, EnsureCapacity
2.40.10.Use StringBuilder Indexer
2.40.11.Demonstrating methods Insert and Remove of the StringBuilder class
2.40.12.Demonstrating method Replace
2.40.13.Use StringBuilder to reverse a string
2.40.14.StringBuilder.ToStrings
2.40.15.Performance difference between String and StringBuilder