增加 Console.Readline 的缓冲区?
Increase buffer for Console.Readline?
我有一行大约 1.5kb 的文本。我想让我的控制台应用程序读取它,但只能粘贴前 255 个字符。如何增加此限制?我实际上是在 visual studio 2013
下的调试模式下使用 Console.ReadLine() 阅读它
来自 MSDN 这样的东西应该有效:
Stream inputStream = Console.OpenStandardInput();
byte[] bytes = new byte[1536]; // 1.5kb
int outputLength = inputStream.Read(bytes, 0, 1536);
您可以将字节数组转换为字符串,例如:
var myStr = System.Text.Encoding.UTF8.GetString(bytes);
这已经讨论过几次了。让我向您介绍我迄今为止看到的最佳解决方案 (Console.ReadLine() max length?)
概念:用 OpenStandartInput 验证 readline 函数(就像评论中提到的那些人一样):
实现:
private static string ReadLine()
{
Stream inputStream = Console.OpenStandardInput(READLINE_BUFFER_SIZE); // declaring a new stream to read data, max readline size
byte[] bytes = new byte[READLINE_BUFFER_SIZE]; // defining array with the max size
int outputLength = inputStream.Read(bytes, 0, READLINE_BUFFER_SIZE); //reading
//Console.WriteLine(outputLength); - just for checking the function
char[] chars = Encoding.UTF7.GetChars(bytes, 0, outputLength); // casting it to a string
return new string(chars); // returning
}
通过这种方式,您可以从控制台获得最大的收益,它的工作空间超过 1.5 KB。
我有一行大约 1.5kb 的文本。我想让我的控制台应用程序读取它,但只能粘贴前 255 个字符。如何增加此限制?我实际上是在 visual studio 2013
下的调试模式下使用 Console.ReadLine() 阅读它来自 MSDN 这样的东西应该有效:
Stream inputStream = Console.OpenStandardInput();
byte[] bytes = new byte[1536]; // 1.5kb
int outputLength = inputStream.Read(bytes, 0, 1536);
您可以将字节数组转换为字符串,例如:
var myStr = System.Text.Encoding.UTF8.GetString(bytes);
这已经讨论过几次了。让我向您介绍我迄今为止看到的最佳解决方案 (Console.ReadLine() max length?)
概念:用 OpenStandartInput 验证 readline 函数(就像评论中提到的那些人一样):
实现:
private static string ReadLine()
{
Stream inputStream = Console.OpenStandardInput(READLINE_BUFFER_SIZE); // declaring a new stream to read data, max readline size
byte[] bytes = new byte[READLINE_BUFFER_SIZE]; // defining array with the max size
int outputLength = inputStream.Read(bytes, 0, READLINE_BUFFER_SIZE); //reading
//Console.WriteLine(outputLength); - just for checking the function
char[] chars = Encoding.UTF7.GetChars(bytes, 0, outputLength); // casting it to a string
return new string(chars); // returning
}
通过这种方式,您可以从控制台获得最大的收益,它的工作空间超过 1.5 KB。