4

私はこれにかなり慣れていません-NSStringstringWithFormatをいくつかのテキストと比較しようとしています。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);
    }
4

2 に答える 2

5

==等しい参照です。文字列比較を行うには、

if([theQuestion isEqualToString:@"The same thing"]){

}
于 2011-08-13T18:01:33.167 に答える
0

そのはず:

NSString *theQuestion = [NSString stringWithFormat:@"%@",@"The same thing"];
于 2011-08-13T18:00:45.227 に答える