在 C# 控制台应用程序中显示阿拉伯字符 [英] Displaying Arabic characters in C# console application

查看:36
本文介绍了在 C# 控制台应用程序中显示阿拉伯字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信 13 多年前,从 Windows ME 开始,就可以在控制台应用程序上显示阿拉伯字符.

现在我在 Windows 8 上使用 Visual Studio 2013,并且显示以下代码:

<块引用>

???????

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

无论如何要在控制台输出中显示阿拉伯字符?

解决方案

要使其正常工作,需要解决几个问题.

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

请参阅知识库文章:我想你可以使用像这样的函数:

static string Reverse(string text){if (text == null) 返回 null;char[] 数组 = text.ToCharArray();Array.Reverse(数组);返回新字符串(数组);}

然后做

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

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("مرحبا بك"));

这篇关于在 C# 控制台应用程序中显示阿拉伯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆