StringBuilder limitations?

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
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!
 
Back
Top