StringBuilder limitations?

G

Guest

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.
 
M

Mattias Sjögren

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
 
G

Guest

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top