cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
luna
Contributor

GS::UniString Does not support Chinese? I have encountered an issue with garbled Chinese characters.

I have encountered an issue with garbled Chinese characters.

 

I have tried many methods but have not been successful, and the Chinese characters will become '?' Or some strange symbols.

 

ac.pngac2.png

 

Please provide me with some ideas, thank you!

2 Solutions

Accepted Solutions
Miklos Vegh
Graphisoft
Graphisoft

Hi,
Of course UniString supports chinese and other languages also. I think that the problem here is the conversion between utf16 and char types.

I suggest using std::wstring instead of std::string in the code.

UniString can be constructed from utf16 character array with the UniString (const UniChar::Layout* uStr) constructor, so you can convert std::wstring to UniString easily.

UniString supports the 8-bit utf8 characters also if needed.

Go to post

Miklos Vegh
Graphisoft
Graphisoft

Or if you have utf8 characters in a file for example, you can construct UniString with this constructor:

char* utf8Chars;

GS::UniString uStr (utf8Chars, CC_UTF8);

Go to post

6 Replies 6
Miklos Vegh
Graphisoft
Graphisoft

Hi,
Of course UniString supports chinese and other languages also. I think that the problem here is the conversion between utf16 and char types.

I suggest using std::wstring instead of std::string in the code.

UniString can be constructed from utf16 character array with the UniString (const UniChar::Layout* uStr) constructor, so you can convert std::wstring to UniString easily.

UniString supports the 8-bit utf8 characters also if needed.

luna
Contributor

Hi, can you provide an example 🙂

std::string str = "D:/ACFiles/中文测试(Chinese Test)";

such as, how to convert 'str' in the above code to GS:: UniString without garbled characters.

 

After trying to convert to wstring, it still doesn't work, just starting from ' Transformed into some strange symbols.

Miklos Vegh
Graphisoft
Graphisoft

I did not compile this code, but I think something like this:

std::wstring wStr = L("中文测试");
GS::UniString uStr (wStr.c_str());

The L() macro forces those characters to compile as utf16.

Miklos Vegh
Graphisoft
Graphisoft

Or if you have utf8 characters in a file for example, you can construct UniString with this constructor:

char* utf8Chars;

GS::UniString uStr (utf8Chars, CC_UTF8);

luna
Contributor

Thank you! 

 

I succeeded 🙂

 

I always thought it was an issue with GS:: UniString, but the problem was that I had previously switched between std:: string and std:: wstring multiple times. xD

 

Miklos Vegh
Graphisoft
Graphisoft

🙂

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!