Objective C Unicode 字符比较 [英] Objective C unicode character comparisons
本文介绍了Objective C Unicode 字符比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
unicode 比较是如何编码的?我需要完全按照下面的方式进行测试,检查字符串中的特定字母.下面的代码窒息:警告:指针和整数之间的比较
How are unicode comparisons coded? I need to test exactly as below, checking for specific letters in a string. The code below chokes: warning: comparison between pointer and integer
for (charIndex = 0; charIndex < [myString length]; charIndex++)
{
unichar testChar = [myString characterAtIndex:charIndex];
if (testChar == "A")
// do something
if (testChar == "B")
// do something
if (testChar == "C")
// do something
}
推荐答案
对于字符文字,使用单引号:
For char literals, use single quotes:
if (testChar == 'A') NSLog(@"It's an A");
或者用代码点编号表示字符:
Or represent the character using the code point number:
if (testChar == 0x1e01) NSLog(@"It's an A with a ring below");
编译器将双引号视为字符串,因此将A"构建为等效于 const char *
(它会为您提供有关指针的错误消息).
The compiler sees double-quotes as a string, so builds "A" as equivalent to a const char *
(which gives you there error message about the pointer).
这篇关于Objective C Unicode 字符比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文