Objective-C中的字符串比较 [英] String comparison in Objective-C

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

问题描述

我目前已经建立了一个网络服务器,该服务器通过SOAP与iPhone应用程序进行通信.我返回的是一个包含GUID的字符串,当我尝试将其与另一个字符串进行比较时,会得到一些奇怪的结果.

I've currently got a webserver set up which I communicate over SOAP with my iPhone app. I am returning a string containing a GUID and when I attempt to compare this with another string I get some strange results.

为什么不触发?当然这两个字符串是匹配的吗?

Why would this not fire? Surely the two strings are a match?

NSString *myString = @"hello world";

if(myString == @"hello world")
    return;

推荐答案

使用-isEqualToString:方法比较两个字符串的值.使用C ==运算符将只比较对象的地址.

Use the -isEqualToString: method to compare the value of two strings. Using the C == operator will simply compare the addresses of the objects.

if ([category isEqualToString:@"Some String"])
{
    // Do stuff...
}

这篇关于Objective-C中的字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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