How to compare two case insensitive strings?

前端 未结 5 362
鱼传尺愫
鱼传尺愫 2021-01-12 17:00

i have 2 string objects containing same string but case is different,now i wanna compare them ignoring the case sensitivity,how to do that??here is the code...



        
5条回答
  •  别那么骄傲
    2021-01-12 17:51

    I would rather suggest to add a category on NSString:

    - (BOOL)isEqualIgnoreCaseToString:(NSString *)iString {
        return ([self caseInsensitiveCompare:iString] == NSOrderedSame);
    }
    

    With this you can simply call:

    [myString1 isEqualIgnoreCaseToString:myString2];
    

提交回复
热议问题