Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Console.Readline() have a limit on the length of text it allows? [duplicate]

Possible Duplicate:
Console.Readline() max length?

In my attempt to find a very simple text to speech application I decided it was faster to write my own. I noticed, however, that Console.Readline() is limited in the amount of text it allows per line to 254 characters; I can't find anything about this limit in the method documentation.

Is this a limitation in the Windows stack, or a problem with my code? How can I overcome it? I could decide to read character by character with Console.Readkey(), but won't I then risk losing characters to the MS DOS dumb text pasting behavior?

like image 271
badp Avatar asked May 21 '11 13:05

badp


People also ask

What is the purpose of console ReadLine () method?

One of the most common uses of the ReadLine method is to pause program execution before clearing the console and displaying new information to it, or to prompt the user to press the Enter key before terminating the application.

How does console ReadLine work C#?

The C# readline method is mainly used to read the complete string until the user presses the Enter key or a newline character is found. Using this method, each line from the standard data input stream can be read. It is also used to pause the console so that the user can take a look at the output.

What is the difference between console read and console ReadLine?

The only difference between the Read() and ReadLine() is that Console. Read is used to read only single character from the standard output device, while Console. ReadLine is used to read a line or string from the standard output device.


1 Answers

This is a somewhat bizarre limitation on the Console API. I had this problem before and found the following solutions:

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

From the following MSDN forum post:

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/51ad87c5-92a3-4bb3-8385-bf66a48d6953

See also this related StackOverflow question:

Console.ReadLine() max length?

like image 197
ColinE Avatar answered Sep 28 '22 10:09

ColinE