unicode 比较是如何编码的?我需要完全按照下面的方式进行测试,检查字符串中的特定字母。下面的代码令人窒息:警告:指针和整数之间的比较
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
}
最佳答案
对于字 rune 字,使用单引号:
if (testChar == 'A') NSLog(@"It's an A");
或者用代码点编号表示字符:
if (testChar == 0x1e01) NSLog(@"It's an A with a ring below");
编译器将双引号视为字符串,因此将“A”构建为等同于 const char *
(它会向您提供有关指针的错误消息)。
关于objective-c - Objective C unicode 字符比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/997776/