So I have been trying to compare two NSStrings in xcode. However, it is not working. What am I doing wrong?
NSString Prog are characters that are xml parsed from mysql
char *cStr = "YES";
NSString *str3 = [NSString stringWithUTF8String:cStr];
if ([str3 isEqualToString:prog]) {
[switch1 setOn:YES animated:YES];
}
else {
[switch1 setOn:NO animated:YES];
}
-[NSString isEqualToString:]
is normally what you would use, and what you are using in such a scenario. Ensure that prog
is a valid NSString
(eg the correct type and not nil
), and keep in mind that string comparison in this implementation is case-sensitive -- ie "Yes"
would not be equal to "YES"
.
使用以下方法比较两个NSString:
[yourString isEqualToString:@"testString"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.