作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用斜杠和破折号创建一个堡垒,我需要使用长音符(上划线)。我尝试了几种方法,但都没有用。任何想法如何使它工作?我得到的不是 Macron,而是“?”
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。
关于c# - c# 控制台应用程序中的 Macron,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42373097/
我正在尝试使用斜杠和破折号创建一个堡垒,我需要使用长音符(上划线)。我尝试了几种方法,但都没有用。任何想法如何使它工作?我得到的不是 Macron,而是“?” using System; using
所以目前我最近经常使用 Unicode。我见过其他人面临同样的问题,但到目前为止没有答案解决我的问题。 目前的目标是能够打印:¯在我的 Windows 控制台窗口中。该字符称为“MACRON”,其Un
我是一名优秀的程序员,十分优秀!