且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

显示阿拉伯字符在C#控制台应用程序

更新时间:2023-11-13 13:40:40

有几个问题需要解决,以得到这个工作。


  • 您需要同时支持阿拉伯语 Windows控制台的字体。

请参阅KB:的字体是在命令窗口中提供必要的标准>


 字体必须是一个固定间距字体。
字体不能为斜体。
该字体不能有负A或C空间。
如果是TrueType字体,它必须是FF_MODERN。
如果它不是一个TrueType字体,它必须是OEM_CHARSET。


块引用>


  • 您必须安装的字体。

有关测试,我用幻觉记忆单,这是支持阿拉伯为数不多。阿拉伯语是一个艰难的语言作出单型字体与由于语言的美观不与固定的宽度为每个字符很好地工作。然而,这种字体使一个诚实的努力。对于其他可能的替代方案,请参阅:

完整,统一等宽code字型?

字体必须安装在正常的方式为您的Windows版本(Vista中/ 7/8,这是单击鼠标右键,在.TTF文件安装) 。一旦做到这一点,你必须遵循的KB方向。


  1. 注册表编辑器 - > HKLM \\软件\\微软\\ WindowsNT的\\ CURRENTVERSION \\控制台\\ TrueTypeFont

  2. 添加一个名为新字符串值 000 与值幻觉记忆国界单

  3. 重新启动

显示阿拉伯字符在C#控制台应用程序

一旦你重新启动,你可以从控制台菜单中选择属性,在字体选项卡更改字体更改控制台的字体。

显示阿拉伯字符在C#控制台应用程序显示阿拉伯字符在C#控制台应用程序

结果。

显示阿拉伯字符在C#控制台应用程序

...所以这一切之后,我们发现,控制台不支持从右到左。语言我想你可以使用类似的函数:

 静态字符串反转(字符串文本)
{
   如果(文字== NULL)返回NULL;
   的char []数组= text.ToCharArray();
   Array.Reverse(数组);
   返回新的字符串(数组);
}

然后执行

  Console.OutputEncoding = System.Text.Encoding.Uni code;
Console.WriteLine(反向(مرحبابك));

显示阿拉伯字符在C#控制台应用程序

I believe it was possible to show Arabic characters on a console application 13+ years ago, since the days of Windows ME.

Now i am using Visual Studio 2013, On a Windows 8, and the following code shows:

????? ??

   Console.OutputEncoding = System.Text.Encoding.Unicode;
   Console.WriteLine("مرحبا بك");

Is there anyway to show Arabic characters in the console output?

There are several issues to resolve to get this to work.

  • You need a font that supports both Arabic AND the windows console.

See KB : Necessary criteria for fonts to be available in a command window

The font must be a fixed-pitch font.
The font cannot be an italic font.
The font cannot have a negative A or C space.
If it is a TrueType font, it must be FF_MODERN.
If it is not a TrueType font, it must be OEM_CHARSET.

  • You must install the font.

For testing, I used DejaVu Mono, which is one of the few that supports Arabic. Arabic is a tough language to make a monotype font with since the aesthetics of the language do not work well with a fixed width for each character. Nevertheless, this font makes an honest effort. For other possible alternatives, see :

complete, monospaced Unicode font?

The font must be installed in the normal way for your version of Windows (in Vista/7/8 this is right-click, Install on the .ttf file). Once this is done, you have to follow the directions in the KB.

  1. Registry Editor --> HKLM\Software\Microsoft\WindowsNT\CurrentVersion\Console\TrueTypeFont
  2. Add a new string value named "000" with the value DejaVu Sans Mono
  3. Reboot

Once you've rebooted, you can change the font in the console by selecting "Properties" from the console menu and changing the font in the "Font" tab.

Result.

... so after all that, we discover that the console does not support Right-To-Left languages. I guess you could use a function like :

static string Reverse(string text)
{
   if (text == null) return null; 
   char[] array = text.ToCharArray();
   Array.Reverse(array);
   return new String(array);
}

and then do

Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.WriteLine(Reverse("مرحبا بك"));