Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to best compare two NSString objects while ignoring case?

I want to compare two strings. It fails when the string have capital letter. How do I convert both string to capitalize and compare.

I have a sample code, can someone correct this.

if ([[txtAnswer.text capitalizedString] isEqualToString:[answer capitalizedString]]) {
     // Do somehing
 }
like image 328
HardCode Avatar asked Dec 04 '22 19:12

HardCode


1 Answers

If you look at the NSString class reference you will see under the heading Identifying and Comparing Strings the methods caseInsensitiveCompare: and localizedCaseInsensitiveCompare:.

like image 154
Jim Avatar answered Mar 04 '23 14:03

Jim