2024-01-16 02:10 AM - last edited on 2024-09-17 11:29 AM by Doreena Deng
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.
Please provide me with some ideas, thank you!
Solved! Go to Solution.
2024-01-17 03:15 PM
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.
2024-01-18 08:42 AM
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);
2024-01-17 03:15 PM
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.
2024-01-18 03:48 AM
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.
2024-01-18 08:38 AM
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.
2024-01-18 08:42 AM
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);
2024-01-18 09:26 AM
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
2024-01-18 09:58 AM
🙂