By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,037 Members | 1,839 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,037 IT Pros & Developers. It's quick & easy.

StringBuilder limitations?

P: n/a
Are there any StringBuilder limitations that I should be aware of?

I'm trying to read a 2,261 byte file into a StringBuilder object with:

string fileName = info.OutputFile;
FileStream fileStream = new FileStream(
fileName, FileMode.Open );
StreamReader file = new StreamReader( fileStream
);
while ( file.Peek() != -1 )
sb.Append( file.ReadLine() + "\n" );
And if the user wishes to see the program output, they click a button on the
application which passes the class variable StringBuilder object to the form.

The form code looks like:

public Form2( StringBuilder sb ) : this()
{
DateTime now = DateTime.Now;
richTxtBox.AppendText( now.ToString() + "\n\r");
richTxtBox.AppendText( sb.ToString() );
}
The problem is that this (relatively small) 2,261 byte file is cut off in
the richTxtBox display.
Mar 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The problem is that this (relatively small) 2,261 byte file is cut off in
the richTxtBox display.


Does the file contain any null characters '\0' ? That would probably
cause the RichTextBox to skip the rest, even though strings and
StringBuilder can contain such characters.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 23 '06 #2

P: n/a
Good call!

After looking at the test application source, I discovered:

f = "%c";

if (test(f, '\0'))
{
pass++;
}
else
{
fail++;
}

Which is C++ code that is writing a null into the file!
"Mattias Sjögren" wrote:
The problem is that this (relatively small) 2,261 byte file is cut off in
the richTxtBox display.


Does the file contain any null characters '\0' ? That would probably
cause the RichTextBox to skip the rest, even though strings and
StringBuilder can contain such characters.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Mar 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.