AppendFormat
Kicks out individual characters or a range from the object. Use Remove to
flush the object
Replace Lets you replace all occurrences of a specified character or a collection of
characters in the object with other specified characters
As you can imagine, this method is heavily overloaded so that you can append the full gamut of data types
into your object.
The following example chews through the long date and time String pushed out by Index Server to inform
you of the last time a file it is stalking was modified:
For intI = 0 To pRow(4).ToString.LastIndexOf("/") + 4
'4 for the year xx/xx/2XXX
sBuilder.Append(pRow(4).ToString.Chars(intI))
Next
So the value "02/02/2002 14:26:47 PM" is reduced to "02/02/2002." You might first grasp for a String
manipulator method, but the For Next loop chews down this particular String like a wolf on lamb ribs.
AppendFormat
The AppendFormat method adds text to the end of the StringBuilder object, but also implements the
IFormattable interface and therefore accepts the standard format Strings described in the formatting section.
You can use this method to customize the format of variables and append those values to a StringBuilder
object. The following code example uses the AppendFormat method to place an integer value formatted as a
currency value at the end of a StringBuilder object:
Dim intI As Integer = 1450
Dim sBuilder As New StringBuilder()
sBuilder.Append("Total remaining is ")
SBuilder.AppendFormat("{0:C}", intI)
Console.WriteLine(sBuilder)
The preceding code snippet writes the following to the console:
Total remaining is $1,450.00
Insert
The Insert method adds a String or object to a specified position in your StringBuilder object. The
following code snippet uses this method to insert a word into the sixth position of a StringBuilder class:
Dim sBuilder As New StringBuilder("Hello Ariel!")
sBuilder.Insert(6, "Beautiful ")
Console.WriteLine(sBuilder)
Remove
You can use the Remove method to remove a specified number of characters from the current StringBuilder
object, beginning at a specified zero−based index. The following code example uses the Remove method to
shorten a StringBuilder's value:
Dim sBuilder As New StringBuilder("Hello Ariel!")
514