【发布时间】:2009-07-23 02:20:25
【问题描述】:
另一个问题。 Unicode、终端,现在是 C# 和 wc。如果我写这段简单的代码
int i=0;
foreach(char c in Console.In.ReadToEnd())
{
if(c!='\n') i++;
}
Console.WriteLine("{0}", i);
并只输入字符“€”(utf-8 中的 3 个字节),wc 返回 3 个字符(可能使用 wint_t,虽然我没有检查),但 ReadToEnd() 返回 1(一个字符) .在这种情况下,ReadToEnd 的行为究竟是什么?我怎么知道ReadToEnd在幕后做什么?
我正在运行使用 utf-8.en.US 初始化的 xterm,运行 Ubuntu Linux 和 Mono。
谢谢。
【问题讨论】: