Assigning all the space to a StringBuilder in advance is a great option when
you know how much space you'll need, but falling back to string
concatenation is not your only other option. A StringBuilder will grow as
needed to accomodate whatever content you Append to it, so that should be
your fallback position--just use a StringBuilder (without pre-setting the
size) and Append. That will still be much faster than plain string
concatenation.
Dim strData As New StringBuilder()
Dim i as integer, arrStr as Array
'arrStr contains contents of the row
For i = 0 to arrStr.Length - 1
strData.Append arrStr.GetValue(i).ToString & ", "
Next
"Ron" <an*******@discussions.microsoft.com> wrote in message
news:09****************************@phx.gbl...
Hello,
I have to read the contents of a textfile and would like
to read it row by row. Each row contains about 180
fields. Most of the data is varchar, but some text fields
(memo fields). So row size varies from 10k to 50k. If I
declare my stringbuilder var like this:
Dim strData As New StringBuilder(50 * 1024)
am I wasting space? Will this defeat the benefits of
using stringbuilder when a row contains only 5k of data as
I loop through the file? My alternative would be this:
Dim str1 As string, i as integer, arrStr as Array
...'arrStr contains contents of the row
For i = 0 to arrStr.Length - 1
str1 += arrStr.GetValue(i).ToString & ", "
Next
Thanks,
Ron