In this section I will show you how you can compare the two strings in your iPhone SDK Project.
To compare the Strings you will have to use the isEqualToString function to compare the strings.
You can simple compare the strings with == operator. In the following example code I have compared the two strings:
NSString *str1 = @"Apple";;
NSString *str2 = @"Orange";
if([str1 isEqualToString: str2]){
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Both strings are equal." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}else{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Strings are not equal" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
The above example is the proper way of comparing strings in iPhone sdk programs. The == operator only compares the pointers, but instead we are comparing the the actual strings.
Hope the above example code will help you in quickly compare the strings.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.