I have a pretty large text file, with very long lines. I am trying to read each line, match a particular field in that line (this is a comma deliminated text file) and then insert the coresponding field. I have done this and it works on most of the files. The problem is with the file that contains very long lines. It just screws everything up. It seems to either be having a problem reading the line as a string, or writing it back to a file. How long can a string be Is there some other method besides streamwriter/reader that can deal with very large lines of text Thanks.

how long can a string be
olidem
Internally, System.String object uses Int32 for its length (m_stringLength or String.Length), hence, we can safely assume that the maximum number of characters a System.String can hold is within the Int32's limit (Int32.Max).
>> Is there some other method besides streamwriter/reader that can deal with very
>> large lines of text
Yes. Try the System.Text.StringBuilder class, it is built for cases like what you described.
Regards,
-chris
hafe
Regards,
-chris
rrlinton
How long is a piece of string
You can use the Read method to read a certain number of characters at a time...
using (StreamReader sr = new StreamReader(path))
{
//This is an arbitrary size for this example.
char[] c = null;
while (sr.Peek() >= 0)
{
c = new char[5];
sr.Read(c, 0, c.Length);
//The output will look odd, because
//only five characters are read at a time.
Console.WriteLine(c);
}
}
...but I'm not sure if the processing you decribed would be possible unless you had the whole line at once.
How exactly does it get 'screwed up'
Prince of Dhump
The good news is that this isn't really much of a limitation, at least at the moment - you can still have a 2GB string, which is likely to cause you bigger grief than not being able to go beyond it :)
Jon