首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目标C stringWithFormat if语句

目标C stringWithFormat if语句
EN

Stack Overflow用户
提问于 2011-08-14 01:57:26
回答 2查看 801关注 0票数 4

我对此非常陌生--我正在尝试将NSString stringWithFormat与一些文本进行比较。它可以很好地与stringWithString配合使用。我不明白为什么它不能和stringWithFormat一起工作?非常感谢任何人能提供的任何帮助!

代码语言:javascript
复制
    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);
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-08-14 02:01:33

==是一个引用等值。要进行字符串比较,它必须是

代码语言:javascript
复制
if([theQuestion isEqualToString:@"The same thing"]){

}
票数 5
EN

Stack Overflow用户

发布于 2011-08-14 02:00:45

它应该是:

代码语言:javascript
复制
NSString *theQuestion = [NSString stringWithFormat:@"%@",@"The same thing"];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7052281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档