我对此非常陌生--我正在尝试将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);
}发布于 2011-08-14 02:01:33
==是一个引用等值。要进行字符串比较,它必须是
if([theQuestion isEqualToString:@"The same thing"]){
}发布于 2011-08-14 02:00:45
它应该是:
NSString *theQuestion = [NSString stringWithFormat:@"%@",@"The same thing"];https://stackoverflow.com/questions/7052281
复制相似问题