Which would work better StringBuilder or String

From reading the forums it looks like if I am going to constantly be changing the value I should use a stringbuilder.

I am creating a text file\report in which I build a string based on dataset fields and then write it out. But it seems like it would be a slow process to clear the string builder each time I write it out and then fill it with 100 spaces again before being able to use it again.

I am converting a foxpro prgram that create a text file to be used for printing checks. So I have to create the code for grouping and making sure the check print on the bottom of the page. Seeing as I can write code similar to this.
Text.write(Field1) at position 26 I am building a string.

Any suggestions?

Thanks.

[723 byte] By [PAPutzback] at [2007-12-17]
# 1
The StringBuilder is used when you want to construct a string in memory by adding many strings to it, like this:

' Bad:
Dim s As String
For i As Integer = 1 To 100
s = s & "Hello"
Next

' Good:
Dim sb As New StringBuilder
For i As Integer = 1 To 100
sb.Append("Hello");
Next
If you're writing out a file, you don't need to create the complete string in memory first:
Dim sw As StreamWriter = File.OpenWrite(fileName)
For Each row As DataRow in table.Rows
sw.WriteLine("{0},{1}", row["Col1"], row["Col2"])
Next
sw.Close

DanielRieck at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic Language...