如何将 Unicode 字符串转换为 TCHAR 系统? [英] How to convert Unicode string to a TCHAR system?
问题描述
我有一个 python (3.6) 代码,它应该将一个 Unicode 字符串传递给一个虚幻引擎项目.虚幻引擎以 TEXT 格式显示文本,我没有错是 Win-Api 的 TCHAR 数组.我在我的平台上看到 TCHAR 是 2 个字节.
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.
这是我在python端编码字符串的方式:
Here is how I encode the string on the python side:
by = bytes(st, 'utf-8')
我尝试编码并传递字符串 "Hello".虚幻得到数据['H', 'e', 'l', 'l', 'o'](每个字符1个字节),并打印"效汬o"(它对待He"和ll"作为单个 Unicode 字符).
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?
- 我是否应该更改 python 端的编码以始终为每个字符生成 2 个字节?
- 我是否应该以某种方式将 unreal 上的结果字节数组解码为 TCHAR Unicode?li>
推荐答案
根据您的配置,TCHAR
映射到 wchar_t
,这是一种使用 UTF- 单边编码的字符类型Windows 上的 16LE.
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')
这篇关于如何将 Unicode 字符串转换为 TCHAR 系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!