我想知道是否有人可以解释这种看似奇怪的行为?
NSString *emptyString = @"";
NSString *aBunchOfAsterisks = @"*********";
NSLog(@"NSString's caseInsensitiveCompare: says the two strings are %@", [emptyString caseInsensitiveCompare:aBunchOfAsterisks] == NSOrderedSame ? @"EQUAL" : @"NOT EQUAL");
NSLog(@"NSComparisonMethods protocol's isCaseInsensitiveLike: says aBunchOfAsterisks is %@ to emptyString", [emptyString isCaseInsensitiveLike:aBunchOfAsterisks] ? @"EQUAL" : @"NOT EQUAL");
NSLog(@"NSComparisonMethods protocol's isCaseInsensitiveLike: says emptyString is %@ to aBunchOfAsterisks", [aBunchOfAsterisks isCaseInsensitiveLike:emptyString]? @"EQUAL" : @"NOT EQUAL");
记录以下内容
NSString的caseInsensitiveCompare:说这两个字符串不
相等
为什么是第二种比较方法,即
[emptyString isCaseInsensitiveLike:aBunchOfAsterisks];
返回是?更糟糕的是,这似乎只有在字符是“ * ”时才会发生。aBunchOfAsterisks中的任何其他值以及所有 3 种比较方式,都返回NO。