wcstombs-用法-Unicode到ASCII [英] wcstombs - usage - Unicode to ascii

查看:116
本文介绍了wcstombs-用法-Unicode到ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要转换为单字节ascii的unicode字符串.

fe ff 00 4d 00 61 00 69 00 6e 00 20 00 42 00 6f 00 61 00 72 00 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .B.o.a.r.d ........

我尝试使用此

size_t已转换= 0;
errno_t er = wcstombs_s(& converted,pL-> szName,64,(const wchar_t *)pLI-> szLayerName,_TRUNCATE);


但它返回错误EILSEQ.我尝试了其他几个版本,但没有任何效果.我想念什么?是开头的BOM(字节顺序标记)吗?

TIA

I have a unicode string that I would like to convert to single byte ascii.

fe ff 00 4d 00 61 00 69 00 6e 00 20 00 42 00 6f 00 61 00 72 00 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 þÿ.M.a.i.n. .B.o.a.r.d...........

I tried using this

size_t converted = 0;
errno_t er = wcstombs_s(&converted, pL->szName, 64, (const wchar_t *)pLI->szLayerName, _TRUNCATE);


but it returns an error EILSEQ. I tried a couple of other versions but nothing is working. What am I missing? Is it the BOM (byte order marker) at the beginning?

TIA

推荐答案

同一件事

Same thing

errno_t er = wcstombs_s(&converted, pL->szName, 64, (const wchar_t *)&pLI->szLayerName[2], _TRUNCATE);


错误EILSEQ


error EILSEQ


这是代码,您是否将字符串输入为"..."之间的字符串或设置了每个字节值的十六进制代码的字节缓冲区?

有人建议我应该忽略BOM表,但这意味着字节顺序为Big Endian,而MS默认为Little Endian,所以我将交换字节并查看会发生什么.

我知道是否将字符串写在记事本中并另存为unicode,所有字节都交换字节顺序.

该字符串实际上来自ghostScript处理由CorelDraw创建的PDF文件,该字符串(内存转储)来自调试器
That is the code, did you enter the string as a string between "..." or a byte buffer setting each byte value with a hex code?

Someone suggested that I should ignore the BOM but that would mean that the byte order is then Big Endian and that MS defaults to Little Endian so I''m going to swap the bytes and see what happens.

I know if I write the string in notepad and save as unicode the byte order is swapped on all bytes.

The string actually comes from ghostScript processing a PDF file created by CorelDraw, the string (memory dump) is from the debugger


Ok,因此忽略BOM和交换字节就可以了.真是PITA.

非常感谢您推动我前进.

交换后的内存看起来像这样

ff fe 4d 00 61 00 69 00 6e 00 20 00 42 00 6f 00 61 00 72 00 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .B.o.a.r.d ...
Ok, so ignoring the BOM and swapping the bytes did the trick. What a PITA.

Thanks much for pushing me on.

The memory after swapping looks like this

ff fe 4d 00 61 00 69 00 6e 00 20 00 42 00 6f 00 61 00 72 00 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ÿþM.a.i.n. .B.o.a.r.d...


这篇关于wcstombs-用法-Unicode到ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆