digitalmars.D.learn - Something about Chinese Disorder Code
- magicdmer (8/8) Nov 24 2015 I display chinese string like:
- Rikki Cattermole (6/14) Nov 24 2015 *A windows API functions are for ASCII only.
- Meta (6/26) Nov 24 2015 I'm pretty sure you can just do:
- Rikki Cattermole (3/29) Nov 24 2015 The second one is correct yes.
- Daniel Murphy (3/13) Dec 01 2015 Either is fine. Non-suffixed string literals have a default type of
- Andrea Fontana (3/11) Nov 24 2015 MessageBoxA <- A is ANSI.
- BLM768 (7/15) Nov 24 2015 You can also try using a wide string literal, i.e. "你好,世界"w. T...
- Marco Leise (28/49) Nov 24 2015 =BC=8C=E4=B8=96=E7=95=8C"w. The=20
- magicdmer (11/14) Nov 24 2015 thank you for your answers.
- Kagamin (2/6) Nov 25 2015 Is it for microsoft runtime or for snn?
- Marc =?UTF-8?B?U2Now7x0eg==?= (3/18) Nov 25 2015 You shouldn't need this cast. Try removing it; if it doesn't
- magicdmer (6/22) Nov 25 2015 Above code is for chinese displaying in windows console,the
- Marc =?UTF-8?B?U2Now7x0eg==?= (7/32) Nov 26 2015 No, I'm talking specifically about the cast in there, not the
- magicdmer (3/9) Nov 26 2015 yes Of course,it works well :)
I display chinese string like: auto str = "你好,世界" writeln(str) and The display is garbled。 some windows api like MessageBoxA ,if string is chinese, it displays disorder code too i think i must use WideCharToMultiByte to convert it , is there any other answer to solve this question simplely
Nov 24 2015
On 24/11/15 10:48 PM, magicdmer wrote:I display chinese string like: auto str = "你好,世界" writeln(str) and The display is garbled。 some windows api like MessageBoxA ,if string is chinese, it displays disorder code too i think i must use WideCharToMultiByte to convert it , is there any other answer to solve this question simplely*A windows API functions are for ASCII only. You need the *W varients which are unicode. For this you could use std.conv : to. wstring text = "my str".to!wstring; Or at least I'm pretty sure that will work for you.
Nov 24 2015
On Tuesday, 24 November 2015 at 09:52:21 UTC, Rikki Cattermole wrote:On 24/11/15 10:48 PM, magicdmer wrote:I'm pretty sure you can just do: wstring text = "my string"; Or auto text = "my string"w;I display chinese string like: auto str = "你好,世界" writeln(str) and The display is garbled。 some windows api like MessageBoxA ,if string is chinese, it displays disorder code too i think i must use WideCharToMultiByte to convert it , is there any other answer to solve this question simplely*A windows API functions are for ASCII only. You need the *W varients which are unicode. For this you could use std.conv : to. wstring text = "my str".to!wstring; Or at least I'm pretty sure that will work for you.
Nov 24 2015
On 25/11/15 1:47 AM, Meta wrote:On Tuesday, 24 November 2015 at 09:52:21 UTC, Rikki Cattermole wrote:The second one is correct yes. I'm just assuming that it isn't compiled into the executable.On 24/11/15 10:48 PM, magicdmer wrote:I'm pretty sure you can just do: wstring text = "my string"; Or auto text = "my string"w;I display chinese string like: auto str = "你好,世界" writeln(str) and The display is garbled。 some windows api like MessageBoxA ,if string is chinese, it displays disorder code too i think i must use WideCharToMultiByte to convert it , is there any other answer to solve this question simplely*A windows API functions are for ASCII only. You need the *W varients which are unicode. For this you could use std.conv : to. wstring text = "my str".to!wstring; Or at least I'm pretty sure that will work for you.
Nov 24 2015
On 25/11/2015 2:16 PM, Rikki Cattermole wrote:On 25/11/15 1:47 AM, Meta wrote:Either is fine. Non-suffixed string literals have a default type of string, but implicitly convert to wstring/dstring at compile time.I'm pretty sure you can just do: wstring text = "my string"; Or auto text = "my string"w;The second one is correct yes. I'm just assuming that it isn't compiled into the executable.
Dec 01 2015
On Tuesday, 24 November 2015 at 09:48:45 UTC, magicdmer wrote:I display chinese string like: auto str = "你好,世界" writeln(str) and The display is garbled。 some windows api like MessageBoxA ,if string is chinese, it displays disorder code too i think i must use WideCharToMultiByte to convert it , is there any other answer to solve this question simplelyMessageBoxA <- A is ANSI. You should try with MessageBoxW, for unicode I guess.
Nov 24 2015
On Tuesday, 24 November 2015 at 09:48:45 UTC, magicdmer wrote:I display chinese string like: auto str = "你好,世界" writeln(str) and The display is garbled。 some windows api like MessageBoxA ,if string is chinese, it displays disorder code too i think i must use WideCharToMultiByte to convert it , is there any other answer to solve this question simplelyYou can also try using a wide string literal, i.e. "你好,世界"w. The suffix forces the string to use 16-bit characters. The garbled display from writeln might be related to your console settings. If you aren't using the UTF-8 codepage in cmd.exe, that would explain why the text appears garbled. Unfortunately, Windows has some significant bugs with UTF-8 in the console.
Nov 24 2015
Am Tue, 24 Nov 2015 17:08:33 +0000 schrieb BLM768 <blm768 gmail.com>:On Tuesday, 24 November 2015 at 09:48:45 UTC, magicdmer wrote:=BC=8C=E4=B8=96=E7=95=8C"w. The=20I display chinese string like: auto str =3D "=E4=BD=A0=E5=A5=BD=EF=BC=8C=E4=B8=96=E7=95=8C" writeln(str) and The display is garbled=E3=80=82 some windows api like MessageBoxA ,if string is chinese, it=20 displays disorder code too i think i must use WideCharToMultiByte to convert it , is there=20 any other answer to solve this question simplely=20 You can also try using a wide string literal, i.e. "=E4=BD=A0=E5=A5=BD=EF=suffix forces the string to use 16-bit characters. =20 The garbled display from writeln might be related to your console=20 settings. If you aren't using the UTF-8 codepage in cmd.exe, that=20 would explain why the text appears garbled. Unfortunately,=20 Windows has some significant bugs with UTF-8 in the console.This is really our problem. We pretend the output terminal is UTF-8 without providing any means to configure the terminal or converting the output to the terminal's encoding. All OSs provide conversion API that works for the most part (assuming normalization form D for example), but we just don't use them. Most contributers were on Linux or English Windows system where the issue is not obvious. But even in Europe =C5=82=C3=A1=C3=B6 will come out garbled. Now this is mostly not an issue with modern Linux and OS X as the default is UTF-8, but some people refuse to change to variable length encodings and Windows has always been preferring fixed length encodings. The proper way to solve this for the OP in a cross-platform way is to replace writeln with something that detects whether the output is a terminal and then converts the string to something that will display correctly, which can be a simple wchar[] on Windows or the use of iconv on Linux. Ketmar is currently using iconv to print D string on his Linux set up for Cyrillic KIO-8U and I think I used it in some code as well. It is not perfect, but will make most printable strings readable. ICU I think is the only library that gets it 100% correct with regards to normalization and offering you different error concealment methods. --=20 Marco
Nov 24 2015
On Tuesday, 24 November 2015 at 19:41:12 UTC, Marco Leise wrote:Am Tue, 24 Nov 2015 17:08:33 +0000 schrieb BLM768 <blm768 gmail.com>: [...]thank you for your answers. I solved it. windows console like: fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china"); auto str = "你好,世界"; writeln(str); MessageBox like: const wchar *wstring = toUTF16z("你好,世界"); MessageBoxW(null,wstring,wstring,0);
Nov 24 2015
On Wednesday, 25 November 2015 at 04:09:29 UTC, magicdmer wrote:fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china"); auto str = "你好,世界"; writeln(str);Is it for microsoft runtime or for snn?
Nov 25 2015
On Wednesday, 25 November 2015 at 04:09:29 UTC, magicdmer wrote:On Tuesday, 24 November 2015 at 19:41:12 UTC, Marco Leise wrote:You shouldn't need this cast. Try removing it; if it doesn't compile, something's wrong.Am Tue, 24 Nov 2015 17:08:33 +0000 schrieb BLM768 <blm768 gmail.com>: [...]thank you for your answers. I solved it. windows console like: fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china");auto str = "你好,世界"; writeln(str); MessageBox like: const wchar *wstring = toUTF16z("你好,世界"); MessageBoxW(null,wstring,wstring,0);
Nov 25 2015
On Wednesday, 25 November 2015 at 12:33:00 UTC, Marc Schütz wrote:On Wednesday, 25 November 2015 at 04:09:29 UTC, magicdmer wrote:Above code is for chinese displaying in windows console,the windows console is acsii,if i remove it,the console will display garbled,look like the following picture http://postimg.org/image/9kf5wdnx1/ so,i must add itOn Tuesday, 24 November 2015 at 19:41:12 UTC, Marco Leise wrote:You shouldn't need this cast. Try removing it; if it doesn't compile, something's wrong.Am Tue, 24 Nov 2015 17:08:33 +0000 schrieb BLM768 <blm768 gmail.com>: [...]thank you for your answers. I solved it. windows console like: fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china");
Nov 25 2015
On Thursday, 26 November 2015 at 01:59:12 UTC, magicdmer wrote:On Wednesday, 25 November 2015 at 12:33:00 UTC, Marc Schütz wrote:No, I'm talking specifically about the cast in there, not the call to setlocale(). Does it still work if you replace this: setlocale(0, cast(char*)"china"); by that: setlocale(0, "china"); ?On Wednesday, 25 November 2015 at 04:09:29 UTC, magicdmer wrote:Above code is for chinese displaying in windows console,the windows console is acsii,if i remove it,the console will display garbled,look like the following picture http://postimg.org/image/9kf5wdnx1/ so,i must add itOn Tuesday, 24 November 2015 at 19:41:12 UTC, Marco Leise wrote:You shouldn't need this cast. Try removing it; if it doesn't compile, something's wrong.Am Tue, 24 Nov 2015 17:08:33 +0000 schrieb BLM768 <blm768 gmail.com>: [...]thank you for your answers. I solved it. windows console like: fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)"china");
Nov 26 2015
On Thursday, 26 November 2015 at 09:59:01 UTC, Marc Schütz wrote:No, I'm talking specifically about the cast in there, not the call to setlocale(). Does it still work if you replace this: setlocale(0, cast(char*)"china"); by that: setlocale(0, "china"); ?yes Of course,it works well :) I copy the code from internet and not notice that,thank you
Nov 26 2015