问题
I have a python (3.6) code that should pass a Unicode string to an Unreal Engine project. The Unreal Engine displays text in TEXT format which I'm not wrong is an array of Win-Api's TCHARs. I saw that on my platform the TCHAR is 2 bytes.
Here is how I encode the string on the python side:
by = bytes(st, 'utf-8')
I tried encoding and passing the string "Hello". The unreal got the data ['H', 'e', 'l', 'l', 'o'] (each char 1 byte), and printed "效汬o" (it treats the "He" and "ll" as a single Unicode character).
How can I fix this?
- Should I change the encoding on the python side to always generate 2 bytes per char?
- Should I decode the result byte array on unreal to TCHAR Unicode somehow?
回答1:
Given your configuration, TCHAR
maps to wchar_t
, a character type that is unilaterally encoded using UTF-16LE on Windows.
You can encode the string using:
by = bytes(st, 'utf-16')
来源:https://stackoverflow.com/questions/52948522/how-to-convert-unicode-string-to-a-tchar-system