www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Chinese characters display correctly under 936 after using the

reply "FrankLike" <1150015857 qq.com> writes:
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
May 16 2014
parent reply "sdvcn" <sdvcn 126.com> writes:
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; }
May 16 2014
parent reply "FrankLike" <1150015857 qq.com> writes:
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.
May 16 2014
parent reply "sdvcn" <sdvcn 126.com> writes:
On Saturday, 17 May 2014 at 06:49:05 UTC, FrankLike wrote:
 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.
import core.stdc.string; char[] s2 = (toMBSz(s1)[0 .. strlen(toMBSz(s1))]).dup; writeln(s2);
May 17 2014
parent reply "FrankLike" <1150015857 qq.com> writes:
 I  mean not  use conv by us,writeln(”中文”),then ok.
 Thank you.
import core.stdc.string; char[] s2 = (toMBSz(s1)[0 .. strlen(toMBSz(s1))]).dup; writeln(s2);
I mean only writeln(s1),transform inside. Thank you.
May 17 2014
parent reply "sdvcn" <sdvcn 126.com> writes:
On Saturday, 17 May 2014 at 07:59:57 UTC, FrankLike wrote:
 I  mean not  use conv by us,writeln(”中文”),then ok.
 Thank you.
import core.stdc.string; char[] s2 = (toMBSz(s1)[0 .. strlen(toMBSz(s1))]).dup; writeln(s2);
I mean only writeln(s1),transform inside. Thank you.
windows Console Support mbs, ansi, Unicode. not support utf8 "s1" is utf8 "cmd /a" ansi "cmd /u" Unicode page code 936 is gbk, s1 Convert gbk Print or page code set "65001" for utf8 fix font to "Lucida Sans Unicode" or s1 to utf16 "cmd /u"
May 17 2014
parent reply "FrankLike" <1150015857 qq.com> writes:
'writeln'  should support unicode,then a lot of characters  can  
work,the D will get a lot of epigones!
Thank you.
May 17 2014
parent "sdvcn" <sdvcn 126.com> writes:
On Saturday, 17 May 2014 at 08:33:07 UTC, FrankLike wrote:
 'writeln'  should support unicode,then a lot of characters  can
  work,the D will get a lot of epigones!
 Thank you.
d support unicode,windows Console The default is not supported unicode.
May 17 2014