比较两个NSStrings [英] Compare two NSStrings

查看:117
本文介绍了比较两个NSStrings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中有一个机制,要求在某一点,两个 NSString s将做同样的事情;因为某种原因,当我比较两者,即使他们是相同的,它仍然不认识到。代码如下:

In my app there is a mechanism that requires that at a certain point two NSStrings will be the same to do something; for some reason when I compare the two, even when they are the same, it still doesn't recognize that. The code is something like this:

NSString * aString = [self someMethodThatGetsAString];

NSString * bString;

BOOL areStringsTheSame = NO;

while (areStringsTheSame != YES) {

       bString = [self someMethodThatTakesNSStringsFromAnArrey];
       if (bString == aString) {
             areStringsTheSame = YES;
       { }



我还插入了一个 NSLog code>,并确保在某一点他们是一样的(就我所知,这是 == 代表...),但仍然没有进入如果更改 BOOL 值。

I even inserted an NSLog() and made sure that at a certain point they were the same (and as far as I know this is what == stands for...), but still it didn't get into the if to change the BOOL value.

有另一种方法来做这个比较吗?

Is there another way to do this comparison? Am I missing something?

推荐答案

您可以使用 isEqualToString:

if ([bString isEqualToString:aString])

= 比较字符串的引用(地址),而不是字符串的值。

== compares the references (addresses of) the strings, and not the value of the strings.

这篇关于比较两个NSStrings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆