Jump to page: 1 2
Thread overview
How to print unicode like: こんにちは 世界
May 19, 2011
Matthew Ong
May 19, 2011
Matthew Ong
May 19, 2011
Matthew Ong
May 19, 2011
Robert Clipsham
Re: How to print unicode like: $B$3(B $B$s(B $B$K(B $B$A(B $B$O(B $B@$3&(B
May 19, 2011
Andrej Mitrovic
Re: How to print unicode like: $B$3(B $B$s(B $B$K(B $B$A(B $B$O(B $B@$3&(B
May 19, 2011
Andrej Mitrovic
Re: How to print unicode like: こ ん に ち は 世界
May 20, 2011
Russel Winder
May 21, 2011
Matthew Ong
May 21, 2011
Matthew Ong
Re: How to print unicode like: $B$3(B $B$s(B $B$K(B $B$A(B $B$O(B $B@$3&(B
May 21, 2011
Andrej Mitrovic
Re: How to print unicode like: こ ん に ち は 世界
May 23, 2011
Matthew Ong
May 19, 2011
Adam D. Ruppe
May 19, 2011
Jesse Phillips
May 19, 2011
Hi,

import std.stdio;
alias immutable(wchar)[] String;
String str="Hello, world; or Καλημέρα κόσμε; or こんにちは 世界";
writeln(str); // It prints garbage on console.

In Java and Go, that just works. I believe UTF-X is handles that.

How to do that within D?

Yes. I am still new to D. No. I am not japanese but chinese.


Matthew Ong

May 19, 2011
AH... The web encoder corrupted the string. into NON human readable.
May 19, 2011
On 5/19/2011 11:22 PM, Matthew Ong wrote:
> Hi,
>
> import std.stdio;
> alias immutable(wchar)[] String;
> String str="Hello, world; orΚαλημέρακόσμε; orこんにちは世界";
> writeln(str); // It prints garbage on console.
>
> In Java and Go, that just works. I believe UTF-X is handles that.
>
> How to do that within D?
>
> Yes. I am still new to D. No. I am not japanese but chinese.
>
>
> Matthew Ong
>

	String str="Hello, world; or Καλημέρα κόσμε; or こんにちは 世界";

-- 
Matthew Ong
email: ongbp@yahoo.com

May 19, 2011
Try using the hex unicode characters like this:

"\u0123"

I don't think decimal characters like you put work in D strings. The &name; syntax sometimes works but only for named chars, and you need to put a \ before them like this:

writeln("\“ hello \”");

Prints:
“ hello ”

You'll have to make sure your console is set to a unicode code page though. This might be done automatically on Windows; I'm not sure.
May 19, 2011
Matthew Ong Wrote:

> Hi,
> 
> import std.stdio;
> alias immutable(wchar)[] String;
> String str="Hello, world; or Καλημέρα κόσμε; or こんにちは 世界";
> writeln(str); // It prints garbage on console.
> 
> In Java and Go, that just works. I believe UTF-X is handles that.
> 
> How to do that within D?
> 
> Yes. I am still new to D. No. I am not japanese but chinese.
> 
> 
> Matthew Ong

consoles tend not to display Unicode, generally you need to tell it to use a font that supports it and I've heard people say you can pass a string to the console to say the output is unicode.

This has been the only issue I've seen people have, D operates just fine with Unicode.

May 19, 2011
On 19/05/2011 16:19, Matthew Ong wrote:
> On 5/19/2011 11:22 PM, Matthew Ong wrote:
>> Hi,
>>
>> import std.stdio;
>> alias immutable(wchar)[] String;
>> String str="Hello, world;
>> orΚαλημέρακόσμε;
>> orこんにちは世界";
>> writeln(str); // It prints garbage on console.
>>
>> In Java and Go, that just works. I believe UTF-X is handles that.
>>
>> How to do that within D?
>>
>> Yes. I am still new to D. No. I am not japanese but chinese.
>>
>>
>> Matthew Ong
>>
>
> String str="Hello, world; or Καλημέρα κόσμε; or こんにちは 世界";
>

There is a built in alias for immutable(wchar)[], wstring. Try postfixing with w, eg:

wstring str = "Hello, world; or Καλημέρα κόσμε; or こんにちは 世界"w;

You could even use auto, given that you postfixed the string with w.

-- 
Robert
http://octarineparrot.com/
May 19, 2011
Which OS?
May 19, 2011
If you're on Windows, you need to set the proper codepage for the console, you can do it programmatically like so:

version(Windows)
{
   import std.c.windows.windows;
   extern(Windows) BOOL SetConsoleOutputCP(UINT);
}

void main()
{
   version(Windows) SetConsoleOutputCP(65001);
   writeln("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界");
}

You would also need a Unicode-aware font, maybe Lucida or something similar. Typically fixed-point fonts used for programming have little support for Unicode characters, and you would get back a black or white box like "[]".


On 5/19/11, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> Which OS?
>
May 20, 2011
On Thu, 2011-05-19 at 22:37 +0200, Andrej Mitrovic wrote:
[ . . . ]
> You would also need a Unicode-aware font, maybe Lucida or something similar. Typically fixed-point fonts used for programming have little support for Unicode characters, and you would get back a black or white box like "[]".

Alternatively use a nice proportional font with Unicode support for code so it is more readable?

Backward compatibility with 80x24 terminals is just so last millennium.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@russel.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


May 21, 2011
On 5/20/2011 2:55 PM, Russel Winder wrote:
> On Thu, 2011-05-19 at 22:37 +0200, Andrej Mitrovic wrote:
> [ . . . ]
>> You would also need a Unicode-aware font, maybe Lucida or something
>> similar. Typically fixed-point fonts used for programming have little
>> support for Unicode characters, and you would get back a black or
>> white box like "[]".
>
> Alternatively use a nice proportional font with Unicode support for code
> so it is more readable?
>
> Backward compatibility with 80x24 terminals is just so last millennium.
>
Hi All,

Thanks for the example code on the unicode issue.

hi Andrej,
version(Windows)
{
   import std.c.windows.windows;
   extern(Windows) BOOL SetConsoleOutputCP(UINT);
}

void main()
{
   version(Windows) SetConsoleOutputCP(65001);
   writeln("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界");
}

I am running this on a M$ Vista Professional edition.

Unfortunately that code sample does not work... Please see attachment.

The reason I am testing this is to understand how the stream library works.

Console test is fundamental test to see if the language handles unicode within the source code itself automatically and display them correctly when it does file IO, network and also GUI level.

Normally in mordern languages it should, because that allow a developer to easily define a simple resource bundle file to loaded automatically within the same fragment of code. If not, then, there is going to be problem. I hope we do not need to write such code:

version(English){
   // some code
}version(Chinese_MainLand){
  // some other code
}version(Chinese_HongKong){
  // yet another code
}...etc

I have originally plan to send an attached screen shot but it is not working for the newsgroup. Perhaps someone can show me how to do that here.

-- 
Matthew Ong
email: ongbp@yahoo.com

« First   ‹ Prev
1 2