Printfn does not give expected results for international (non-Latin) characters

I have the following program:

let txt = "إتصالات" printfn "Text is: %s" txt 0 // return an integer exit code 

The txt value is set to some Arabic characters. When I run the program, what is displayed on the console is a bunch of question marks, not characters. The Visual Studio 2012 debugger displays the correct characters for the txt variable.

What am I doing wrong and how to display international characters correctly?

+4
source share
1 answer

According to How to write Unicode characters to the console? you need to set the OutputEncoding property on the console, for example:

 System.Console.OutputEncoding <- System.Text.Encoding.Unicode let txt = "إتصالات" printfn "Text is: %s" txt 0 // return an integer exit code 

The answer to this question is worth reading, because it also describes why you need to change your console font to really do the job, and also how to do it.

Here are some additional links with additional information:

Update. Since the text in the Arabic text in the example just works fine on StackOverflow, I looked in CSS to see which fonts they use to render pre-formatted text. Using this list and the Windows Symbol Map tool (Start → All Programs → Accessories → System Tools → Symbol Map), I found that the Courier New font (which comes with Windows) supports Arabic characters. If you use the hacked registry in the link "Windows Console and TrueType Fonts" (see above), you can add Courier New as a font that you can use in the console.

+9
source

Source: https://habr.com/ru/post/1490149/


All Articles