Joe Wood's Blog

Technology

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Subscriptions



There has to be an easier way - ReadLine text limit to 256 chars

Typical Friday afternoon problem.  My console application works fine, the only problem is that Console.ReadLine maxs out at 256 characters.  This application definitely needed the capacity for much larger strings and I didn't want to split it across multiple lines.

Searching for this problem I found nothing - it seems to be the default buffer size on the input stream attached to Console.In.  But surely somebody else had hit this problem before??

Anyway, my solution is dirty.  Dirty enough to post here and ask for a better one:

byte[] bytes = new byte[2560]; // or any large size you can imagine
// create a new input stream with the large buffer size
Stream inputStream = Console.OpenStandardInput(bytes.Length);
// read up to the length of tbe buffer
int bufferSize = inputStream.Read(bytes,0,bytes.Length);
// take two away for CR,LF
string command = Encoding.ASCII.GetString(bytes,0,bufferSize-Environment.NewLine.Length);

This works for any size buffer based on the size sent to the OpenStandardInput method.

posted on Monday, January 31, 2005 12:17 PM by joewood





Powered by Dot Net Junkies, by Telligent Systems