Is there any way to write Hebrew in the Windows Console?
Asked Answered
A

5

9

Is there any way to write Hebrew in the Windows Console?

I tried the following:

Console.OutputEncoding = new UTF8Encoding(false);
Console.WriteLine("\u05D0\u05D1");
Console.ReadLine();

but instead of "אב" it writes some other Unicode character, that're not in the Hebrew ABC.

Any ideas why?

Averyaveryl answered 6/2, 2010 at 15:29 Comment(0)
L
4

If you can call chcp command before your program, you can change the codepage to Hebrew and then your characters will be readable. There is an interesting article about internationalization and windows console here: http://illegalargumentexception.blogspot.com/2009/04/i18n-unicode-at-windows-command-prompt.html

Laynelayney answered 6/2, 2010 at 15:39 Comment(1)
ariely.info/Blog/tabid/83/EntryId/139/… chcp 862 and "courier new"Naturalist
S
9

Simply change the OutputEncoding:

Console.OutputEncoding = Encoding.GetEncoding("Windows-1255");
Stines answered 18/5, 2017 at 0:34 Comment(0)
L
4

If you can call chcp command before your program, you can change the codepage to Hebrew and then your characters will be readable. There is an interesting article about internationalization and windows console here: http://illegalargumentexception.blogspot.com/2009/04/i18n-unicode-at-windows-command-prompt.html

Laynelayney answered 6/2, 2010 at 15:39 Comment(1)
ariely.info/Blog/tabid/83/EntryId/139/… chcp 862 and "courier new"Naturalist
S
3
        Console.OutputEncoding = new UTF8Encoding();
        Console.WriteLine("\u05D0\u05D1");
        Console.WriteLine("אריאל");
        Console.WriteLine(new string("אריאל".Reverse().ToArray()));

works for me, maybe is just about removing the "false"? this is working in my machine, except o.c. it writes the letters backwards, unless i use reverse

maybe you need to set the registry? run -> regedit and do this: http://blogs.microsoft.co.il/technet/2013/06/11/%D7%90%D7%99%D7%9A-%D7%90%D7%A4%D7%A9%D7%A8-%D7%9C%D7%A8%D7%90%D7%95%D7%AA-%D7%A2%D7%91%D7%A8%D7%99%D7%AA-%D7%91-powershell-console/

in the registry window rightclick choose new string.

Sinter answered 1/1, 2015 at 12:13 Comment(1)
The above seems not to work in the current version of powershell. I get an error on the first line.Grum
M
0

Correct me if I'm wrong but I don't think the console supports UTF8.

Mcdade answered 6/2, 2010 at 15:34 Comment(2)
Apparently it doesn't (see below).Mcdade
The console has broken support for UTF-8. Windows has a codepage 65001 which you can set in the console via an API or from cmd by typing chcp 65001. However there is a bug in the Windows WriteFile() API when using this codepage which returns the number of Unicode characters written instead of the documented number of bytes written. If .net or C# compares this result to check if a write was successful then it will not work. This API bug is behind Perl, PHP, and Ruby not working under codepage 65001 and various problems in the Visual C runtime library.Cluj
T
0

In case you just want it for short testing purposes and not to build an entire application, just use Debug.WriteLine that does support unicode (tested with heb chars only).

Tactile answered 2/2, 2012 at 3:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.