谁能告诉我Objective C中不区分大小写比较的资料?它似乎没有与str1.equalsIgnoreCase(str2)等效的方法


当前回答

NSMutableArray *arrSearchData;  
NSArray *data=[arrNearByData objectAtIndex:i];
NSString *strValue=[NSString stringWithFormat:@"%@", [data valueForKey:@"restName"]];
NSRange r = [strValue rangeOfString:key options:NSCaseInsensitiveSearch];

if(r.location != NSNotFound)
{
     [arrSearchData addObject:data];
}

其他回答

一种新的方法。iOS 8

let string: NSString = "Café"
let substring: NSString = "É"

string.localizedCaseInsensitiveContainsString(substring) // true

把Jason Coco的答案转换成Swift的懒人版:)

if ("Some String" .caseInsensitiveCompare("some string") == .OrderedSame)
{
  // Strings are equal.
}
if( [@"Some String" caseInsensitiveCompare:@"some string"] == NSOrderedSame ) {
  // strings are equal except for possibly case
}

文档位于搜索和比较方法

- (NSComparisonResult)caseInsensitiveCompare:(NSString *)aString

来检查iPhone ContactApp中的前缀

([string rangeOfString:prefixString options:NSCaseInsensitiveSearch].location == 0)

这个博客对我很有用