Case-insensitive NSString comparison

前端 未结 4 1515
梦毁少年i
梦毁少年i 2021-02-05 19:35

Using this code I am able to compare string values.

[elementName isEqualToString: @\"Response\"]

But this compares case-sensitively. Is there a

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 20:04

    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?

提交回复
热议问题