How to compare two case insensitive strings?

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

    If you look up caseInsensitiveCompare: in the docs you'll see that it returns an NSComparisonResult rather than a BOOL. Look that up in the docs and you'll see that you probably want it to be NSOrderedSame. So

    if ([myString1 caseInsensitiveCompare:myString2] == NSOrderedSame)

    should do the trick. Or just compare the lowercase strings like Robert suggested.

提交回复
热议问题