Search code examples
.netconsole.readline

Increase buffer for Console.Readline?


I have a line that is about 1.5kb of text. I want my console app to read it but only the first 255 characters can be pasted in. How do I increase this limit? I am literally reading it using Console.ReadLine() in debug mode under visual studio 2013


Solution

  • From MSDN something like this ought to work:

    Stream inputStream = Console.OpenStandardInput();
    byte[] bytes = new byte[1536];    // 1.5kb
    int outputLength = inputStream.Read(bytes, 0, 1536);
    

    The you can convert your byte array to a string with something like:

    var myStr = System.Text.Encoding.UTF8.GetString(bytes);