JonnyBoats
JonnyBoats

Reputation: 5187

printfn not producing 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 value of txt is being set to some Arabic characters. When I run the program what is being displayed on the console is a bunch of question marks rather than the characters. In the Visual Studio 2012 debugger the correct characters are being displayed for the txt variable.

What am I doing wrong and how does one properly display international characters?

Upvotes: 4

Views: 490

Answers (1)

Jack P.
Jack P.

Reputation: 11525

According to How to write unicode chars to console? you need to set the OutputEncoding property on the console, like this:

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

The answer for that question is worth reading though, because it also describes why you need to change your console font to really make this work, and also how to do it.

Here are some additional links with more information:

Update: Since the Arabic text in the example renders just fine here on StackOverflow, I peeked at the CSS to see which fonts they're using to render preformatted text. Using that list and the Windows Character Map tool (Start -> All Programs -> Accessories -> System Tools -> Character Map), I've found the Courier New font (which ships with Windows) supports Arabic characters. If you use the registry hack in the "Windows Console and TrueType Fonts" link (above), you should be able to add Courier New as a font you can use in the console.

Upvotes: 9

Related Questions