Chinese characters display correctly under 936 after using the Function CharToOemW

FrankLike via Digitalmars-d digitalmars-d at puremagic.com
Fri May 16 23:49:04 PDT 2014


On Saturday, 17 May 2014 at 03:30:14 UTC, sdvcn wrote:
> On Saturday, 17 May 2014 at 03:17:46 UTC, FrankLike wrote:
>> Hi,everyone,
>>
>> Many Chinese coders found  under Chinese characters were not 
>> display correctly under CodePage 936,but if use the Function 
>> CharToOemW,it's ok.
>>
>> import std.c.stdio;
>> import std.c.windows.windows;
>> import std.stdio;
>>
>> extern (Windows) {
>>    export BOOL CharToOemW(
>>            LPCWSTR lpszSrc, // string to translate
>>            LPSTR lpszDst // translated string
>>    );
>> }
>>
>> void main()
>> {
>>    wchar[] s =cast(wchar[]) "中文"; //Greek salutation 
>> //"Χαίρετε!"~
>> 	 writeln(s);
>> 	echo(s,"");
>> }
>>
>> void echo(wchar[] s,string page)
>> {
>> 	//system("chcp "~page);
>>    char[] t = new char[s.length];
>>    CharToOemW(cast(const(wchar)*)s, cast(char*)t); // calling 
>> Windows API function
>>    puts(cast(char*)t); // printing translated string
>> }
>>
>> Now,it  displays correctly under 936.
>>
>> So,writeln etc. function should use the    Windows API 
>> Function on windows.
>> It's ok?
>>
>> Frank
>
> 没必要那么麻烦吧~
>
> import std.conv;
>
> import std.windows.charset;
>
> int main(string[] argv)
> {
>
> 	auto s1 = "中文";//utf8 字符串
> 	writeln("word:"~ s1); //乱的
> 	writeln("word:" ~ to!string(toMBSz(text(s1)))); //转后就正常了
>
>
>
>     writeln("Hello D-World!");
>     return 0;
> }

I  mean not  use conv by us,writeln(”中文”),then ok.
Thank you.



More information about the Digitalmars-d mailing list