How to compare two case insensitive strings?

前端 未结 5 364
鱼传尺愫
鱼传尺愫 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:47

    To save a method call, I used a macro via a #define:

    #define isEqualIgnoreCaseToString(string1, string2) ([string1 caseInsensitiveCompare:string2] == NSOrderedSame)
    

    Then call:

    (BOOL) option = isEqualIgnoreCaseToString(compareString, toString);
    

提交回复
热议问题