我对此很新 - 我正在尝试将NSString stringWithFormat与一些文本进行比较。它与stringWithString一起工作正常。我无法弄清楚为什么它不能与stringWithFormat一起使用? 非常感谢任何人提供的任何帮助!
NSString *theQuestion = [NSString stringWithFormat:@"The same thing"];
if (theQuestion == @"The same thing"){
NSLog(@"stringWithFormat is the same as the given text");
}else{
NSLog(@"stringWithFormat is NOT the same as the given text");
NSLog(@"but theQuestion is:\"%@\"", theQuestion);
}
答案 0 :(得分:5)
==
是一个相等的参考。做一个字符串比较它必须是
if([theQuestion isEqualToString:@"The same thing"]){
}
答案 1 :(得分:0)
应该是:
NSString *theQuestion = [NSString stringWithFormat:@"%@",@"The same thing"];