加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何检查c中字符的unicode值的范围

发布时间:2020-12-16 07:06:39 所属栏目:百科 来源:网络整理
导读:我是C的新手,来自非CS背景.因此,如果这个问题很愚蠢或以前得到回答,请原谅我. 我在c中有一个字符串,语言是泰卢固语. std::string str = "????"; // (it means exists; pronounced as Vundi)std::string substring = str.substr(0,3); 上面的子串将是“?”(发
我是C的新手,来自非CS背景.因此,如果这个问题很愚蠢或以前得到回答,请原谅我.

我在c中有一个字符串,语言是泰卢固语.

std::string str = "????"; // (it means exists; pronounced as Vundi)
std::string substring = str.substr(0,3);

上面的子串将是“?”(发音为Vu),其unicode十六进制值为0C09.

如何从子字符串中获取值0C09?
目的是检查子串是否在Telugu(0C00-0C7F)的有效范围内.

我已经看到了他们应用于obj-c,java,php,c#等的其他问题.我正在寻找使用std :: string的c.

根据评论,我在joelonsoftware.com/articles/Unicode.html阅读了这篇文章.

让我用更多信息更新我的问题.
我使用的是Fedora 19 x86_64,编码是UTF-8.控制台能够正确显示文本.

根据文章,如果我理解正确ASCII是单字节字符,unicode是多字节字符.上面的代码示例反映了这里,每个unicode字符的长度为3个字节.除了讨论UTF-8 /文本编码和多字节字符之外,本文没有提供检测unicode字符串语言的实际帮助.

也许我应该重新解释我的问题:

如何在C中检测unicode字符串的语言?

在此先感谢您的帮助.

解决方法

使用字符串我得到的结果是

std::string str = "????"; // (it means exists; pronounced as Vundi)
unsigned short i =str[0];
printf("%x %d",i,i);

输出是“ffeo 65504”

但是当我使用wstring时

std::wstring str = L"????"; // (it means exists; pronounced as Vundi)
unsigned short i =str[0];
printf("%x %d",i);

输出是“c09 3081”,我认为是正确的输出.我不确定,但那就是你想要的.让我知道

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读