Case-insensitive NSString comparison

user198725878 picture user198725878 · Dec 20, 2010 · Viewed 41.3k times · Source

Using this code I am able to compare string values.

[elementName isEqualToString: @"Response"]

But this compares case-sensitively. Is there a way to compare the string without case sensitivity?

Answer

zoul picture zoul · Dec 20, 2010

There’s a caseInsensitiveCompare: method on NSString, why don’t you read the documentation? The method returns NSComparisonResult:

enum {
   NSOrderedAscending = -1,
   NSOrderedSame,
   NSOrderedDescending
};
typedef NSInteger NSComparisonResult;

…ah, sorry, just now I realized you are asking for case sensitive equality. (Why don’t I read the question? :-) The default isEqual: or isEqualToString: equality should already be case sensitive, what gives?