[英]Macron in c# console application
我正在尝试使用斜杠和破折号创建堡垒,并且需要使用macron(overscore)。 我尝试了几种方法,但没有一种起作用。 有什么想法使它起作用吗? 而不是马克龙我得到'?'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kingsdom
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
string ups = new string ('^', n / 2);
string midUps = new string('_' ,(n * 2) - (((n / 2) * 2) + 4));
string whitespaces = new string(' ', (n * 2) - 2);
string downs = new string('_', n / 2);
string midDowns = new string('\u203E', (n * 2) - (((n / 2) * 2) + 4));
Console.WriteLine("{0}{1}{2}{3}{0}{1}{2}", "/", ups, "\\", midUps);
for (int i = 0; i < n - 2; i++)
{
Console.WriteLine("{0}{1}{0}", "|", whitespaces);
}
Console.WriteLine("{0}{1}{2}{3}{0}{1}{2}", "\\", downs, "/", midDowns);
}
}
}
控制台可以使用不同的代码页显示文本。 并非所有这些代码页都可以正确显示所有字符。 例如,当您使用代码页855(这是使用带有西里尔字母的东欧语言的Windows系统的默认页)时,无法显示Macron字符。
您可以通过在Main函数开始处设置Console.OutputEncoding
来定义用于自己的控制台输出的代码页:
Console.OutputEncoding = Encoding.Unicode;
这样可以使控制台可以显示任何Unicode字符。
如果要使用特定的代码页,例如437(美国),则应编写:
Console.OutputEncoding = Encoding.GetEncoding(437);
请注意,在此位置使用Encoding.Unicode
至少需要.net 4.5版。
有关更多详细信息,请参见属性Console.OutputEncoding的文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.