C#: Large amounts of text cut off when read by program

445 Views Asked by At

Hi I cant seem to find any useful information regarding how to store information into an array from a console.writeline.

 Console.WriteLine("Please enter one or more sentences.");
 string text = Console.ReadLine();

How would I store the users sentence into an array? as currently if I enter a large amount of text it is getting cut of hopefully an array will allow for all of the text to be read and sorted. Thank you!!

2

There are 2 best solutions below

1
On BEST ANSWER

It's a limit of the Console API, it is 256 characters (254 + CR LF). You can change this limit with

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

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

OR

you can create a new ReadLine method, check this post: Console.ReadLine() max length?

0
On

You can establish an way of communication with the user, like when he send an empty line it ends. And then do the following:

Console.WriteLine("Please enter one or more sentences.");
string text;    
List<string> list = new List();

while (true) 
{
       text = Console.ReadLine();

      if (text.Length == 0)
          break;
      else
          list.Add(text);             
}