Notes

.NET - Increase Console.Readline 254 character limit

author: Paul Kim

categories: dotnet

tags: dotnet

How to read more than 254 characters with Console.Readline()

Console.ReadLine() has a 254 character read limit.

// set a default buffer size of 4000
private static string ReadLine(int bufferSize = 4000) {
  var inputStream = Console.OpenStandardInput(bufferSize);
  var bytes = new byte[bufferSize];
  //Console.WriteLine(outputLength);
  return new string(Encoding.UTF7.GetChars(bytes, 0, inputStream.Read(bytes, 0, bufferSize)));
}

Another possible solution:

Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));

ChromeEdgeFirefoxOpera

© 2021 paulkode.com. All rights reserved.