特殊字符转int,然后返回
所以我想要的是将字母“a”转换为97(例如在ASCII表中),然后将67转换为“a”。 实际上,我执行了大量数学运算,将其视为二进制数 - 因此转换是必要的。 然而,对于特殊字符,它的效果并不好。
char c = 'ÿ';
int i = int(c);
wchar_t wTemp = static_cast<wchar_t>(i);
wchar_t* w = &wTemp;
String^ newI = gcnew String(w);
该符号只是我在图像中发现的随机符号(需要读取的字符类型)。它只是作为一个完全不同的符号出现。我不知道为什么,或者该怎么办?
So what I want, is for example to convert the letter 'a' into 97 (such as it is in the ASCII table), and then convert 67 into 'a'.
I actually perform a load of mathematics and stuff to the letter, treating it as binary number - so the transition is necessary.
However for special characters it is not working nicely.
char c = 'ÿ';
int i = int(c);
wchar_t wTemp = static_cast<wchar_t>(i);
wchar_t* w = &wTemp;
String^ newI = gcnew String(w);
That symbol is just a random one I found in an image (the type of character that will need to be read). It just comes out as a completely different symbol. I have no idea why, or what to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
0x7f (127) 以上的字符可能会转换为负整数值。也许将
c
更改为无符号:Characters above 0x7f (127) are probably converting to negative integer values. Maybe change
c
to unsigned:尽管我没有运行你的代码,但我看起来不太正确。下面是来自 MSDN 的一个很好的示例,说明如何在 wchar_t 之间进行转换:
http://msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx
我不认为“特殊”字符有什么特别之处。
Your code doesn't look quite right to me though I didn't run it. Here is a good example from MSDN how to convert from and to wchar_t:
http://msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx
I don't believe there is anything special about 'special' characters.