Language Support - Read and Write

Marco Leise Marco.Leise at gmx.de
Sun Dec 15 05:52:44 PST 2013


Am Sun, 15 Dec 2013 11:19:43 +0100
schrieb "Siavash Babaei" <siavash.babaei at gmail.com>:

> Yes and No: I kind of knew that and just wanted to make sure. 
> Thank you for confirming it. On the other hand, when I define a 
> string variable and set it to say, "سلام", and want to output it 
> to the CMD (write, writeln, writef), what I get is gibberish and 
> CMD is set correctly BTW.

If you use an older version of Windows you might have to change
the console font to "Lucida" I think it was to support a wider
range of characters.
Then there is a reason why Java has a complicated encoding
system for console output. While on Linux the console uses
UTF-8 (in line with D) for a few years now, the Windows
console usually expects Latin-1 or UTF-16. writeln() doesn't
take this into consideration and I had issues even with German
umlauts on Windows. It worked best when I used the Windows API
directly to write UTF-16 to the console, prefixed with a
byte-order-mark. That together with switching the console font
to Lucida, should give you proper printing of non-ASCII
characters.

If this sounds overly complicated, take a look at Java:
http://stackoverflow.com/questions/2415597/java-how-to-detect-and-change-encoding-of-system-console

The result is different on Windows, Linux and even Mac unless
you work closely with the specific console implementation of
the operating system. A general "writeln" doesn't cut it
unless you are on Linux or write to files or "pipe" the output
to another program understanding UTF-8.

-- 
Marco



More information about the Digitalmars-d-learn mailing list