views:

491

answers:

4

Hi,

Can anyone point me to any resources about case insensitive comparison in Objective C? It doesn't seem to have an equivalent method to str1.equalsIgnoreCase(str2)

Thanks,
Teja

+3  A: 
- (NSComparisonResult)caseInsensitiveCompare:(NSString *)aString
WhirlWind
+8  A: 
if( [@"Some String" caseInsensitiveCompare:@"some string"] == NSOrderedSame ) {
  // strings are equal except for possibly case
}

The documentation is located at http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/uid/20000154-caseInsensitiveCompare_

Jason Coco
A: 

Try this method - (NSComparisonResult)caseInsensitiveCompare:(NSString *)aString

Reena
+1  A: 

An alternative if you want more control than just case insensitivity is:

[someString compare:otherString options:NSCaseInsensitiveSearch];

Numeric search and diacritical insensitivity are two handy options.

drawnonward