简体   繁体   English

010 编辑器模板:将 int 转换为 wchar_t

[英]010 Editor template: convert a int to wchar_t

I'm reading a single wchar_t character from a binary file in 010 template in this way我正在以这种方式从 010 模板中的二进制文件中读取单个wchar_t字符

wchar_t character;

it will give me for example 64 for @, after that I need to add 0x20 to the 64 so it should be 96 now它会给我例如@的64 ,之后我需要将0x20添加到64,所以现在应该是96
my question is how can I convert the output after add operation to wchar_t (or string) again in 010 template?我的问题是如何在 010 模板中再次add操作后的输出转换为 wchar_t(或字符串)?

Presumably you are adding 0x20 to convert upper case ASCII letter to lower case.据推测,您正在添加0x20以将大写 ASCII 字母转换为小写。 In this specific case it is safe, as long as this is for code points in ASCII range.在这种特定情况下,它是安全的,只要这是针对 ASCII 范围内的代码点。

But these operations are not valid in general.但是这些操作通常是无效的。 UTF16 uses surrogate pairs for some code points, each code point can be 2 wchar_t . UTF16 对某些代码点使用代理对,每个代码点可以是 2 wchar_t So in Windows for example, a code point is represented by 2-bytes or 4-bytes, you can't mess around with half it.因此,例如在 Windows 中,代码点由 2 字节或 4 字节表示,您不能乱用一半。

Use functions such as _strlwr to convert a string to lower case.使用_strlwr_strlwr将字符串转换为小写。

If reading ASCII characters between 0 and 128, it is guaranteed that these characters are not surrogate.如果读取 0 到 128 之间的 ASCII 字符,则保证这些字符不是代理字符。 This makes easy for example, if you are looking for \\n \\t A . , ; :例如,如果您正在寻找\\n \\t A . , ; : ,这很容易\\n \\t A . , ; : \\n \\t A . , ; : \\n \\t A . , ; : , etc. \\n \\t A . , ; :

Use towlower if available, and wprintf for printing wchar_t如果可用,请使用towlower ,并使用wprintf打印wchar_t

wint_t wch = towlower(L'A');
wprintf(L"%c", wch);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM