Rich,
As Marcie suggests its easier to create a new StringBuilder when you need to
"clear" it.
Depending on the size and "ownership" of StringBuilders involved I will
consider setting the length of the StringBuilder to zero rather then
creating a new one. This potentially "limits" the amount of work the GC
needs to do as you are limiting the amount of objects created, however it
also may cause more work for the GC, as the single instance of the
StringBuilder may be promoted to generation 1 or 2...
Something like:
| Dim strData As StringBuilder
|
| For i = 1 to 500000
strData.Length = 0
| For j = 0 to ColVal.Length
| strData.Append ColVal(j) & ", "
| Next
| oWrite.WriteLine(strData.ToString())
| Next
Which is "Better" (length = 0 or new stringbuilder) really depends on the
dynamics of each individual program...
However! in your example I don't think I would bother with a StringBuilder,
rather I would simply write to the output file directly.
| For i = 1 to 500000
| For j = 0 to ColVal.Length
oWrite.Write(ColVal(j))
oWrite.Write(",")
| Next
| oWrite.WriteLine()
| Next
Hope this helps
Jay
"Rich P" <rp*****@aol.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
|I have to read data from an external source, massage the data,
| concatenate it to one long string, then write it to a textfile. So I am
| experimenting with the StringBuilder object. I append the data in a
| loop, then I write the data
| to text file, then I need to clear the StringBuilder object for the next
| row of data. First, is this the proper use of the StringBuilder object?
| Second, I am clearing the object using the Remove method starting at
| point 0 and
| StringBuilderObject.Length. Is this correct for clearing the object?
|
| Imports System.Text
| ..
| Dim strData As New StringBuilder
| ..
| strData.Append ....
| ..
| strDate.Remove(0, strData.Length)
|
| Thanks,
| Rich
|
| *** Sent via Developersdex
http://www.developersdex.com ***