xcode iOS compare strings xcode iOS compare strings ios ios

xcode iOS compare strings

I assume that webresult is an NSString. If that is the case, then you want to use:

if ([webresult isEqualToString:cmp]) {

instead of:

if (webresult == cmp) {

as the above method checks if the strings are equal character by character, whereas the bottom method checks if the two strings are the same pointer. Hope that helps!

if (webresult == cmp)

Here, == checks whether webresult, cmp are pointing to the same reference or not. You should instead compare value of the object by using NSString::isEqualToString.

 if ( [ cmp isEqualToString:webresult ]) {   // .. }else {   // .. }

Note that isEqualToString is a good option because it returns boolean value.

We cannot comapre the strings with ==
We have to use isEqualToString:

if([str1 isEqualToString:str2]){}else{}