我该如何重新present一个统一code字符文本字符串ISO / ANSI C时,字符集是ASCII? [英] How do I represent a Unicode character in a literal string ISO/ANSI C when the character set is ASCII?
本文介绍了我该如何重新present一个统一code字符文本字符串ISO / ANSI C时,字符集是ASCII?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Perl中,我可以说
我的$ S =r \\ X {} E9总和\\ X {E9};
分配简历
到 $ S
。我想要做C.类似的东西我特别想说
sometype_that_can_hold_utf8 C = get_utf8_char();
如果(℃下'\\ X {E9}'){
/* 做一点事 */
}
解决方案
有关UTF8,你必须使用规则中,例如生成自己的编码,的此处。例如,德国的sharp s(SS,code点0xdf),具有UTF8编码0xc3,0x9f。您的E-急性(E,code点0xe9)有0xc3,0xa9的UTF8编码。
你可以把任意的十六进制字符在你的字符串有:
的char * CV =r \\ XC3 \\ xa9sum \\ XC3版权所有\\ xA9
字符*锐器=\\ XC3 \\ x9f
In Perl, I can say
my $s = "r\x{e9}sum\x{e9}";
to assign "résumé"
to $s
. I want to do something similar in C. Specifically, I want to say
sometype_that_can_hold_utf8 c = get_utf8_char();
if (c < '\x{e9}') {
/* do something */
}
解决方案
For UTF8, you have to generate the encoding yourself using rules found, for example, here. For example, the German sharp s (ß, code point 0xdf), has the UTF8 encoding 0xc3,0x9f. Your e-acute (é, code point 0xe9) has a UTF8 encoding of 0xc3,0xa9.
And you can put arbitrary hex characters in your strings with:
char *cv = "r\xc3\xa9sum\xc3\xa9";
char *sharpS = "\xc3\x9f";
这篇关于我该如何重新present一个统一code字符文本字符串ISO / ANSI C时,字符集是ASCII?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文