Objective-C 中的字符串比较

发布于 2024-11-04 13:01:03 字数 557 浏览 0 评论 0原文

如果无法实现这一点,我觉得真的很愚蠢。 我只是说,如果:在我的xml中标记,“tipo”包含“Colonnina”做一些事情

if ([[colonninaElencoFeed objectAtIndex:indexPath.row]objectAtIndex:@"tipo"] = @"Colonnina" ){
do something ...
}

当然我知道你不能写这样的语法,这个例子让我们更好地理解我正在尝试做的事情,

不用说XML 的写法是这样的

<tipo>Colonnina</tipo>

,我已经在使用这种方法从 xml 中推断数据,这样没有任何问题

cell.textLabel.text = [NSString stringWithFormat:@"%@", [[colonninaElencoFeed objectAtIndex:indexPath.row]objectForKey:@"title"]];

,我希望你能帮助我,谢谢

I feel really stupid not be able to achieve this if.
I simply say, if: tag in my xml, "tipo" contains "Colonnina" do something

if ([[colonninaElencoFeed objectAtIndex:indexPath.row]objectAtIndex:@"tipo"] = @"Colonnina" ){
do something ...
}

of course I know that you can not write so the syntax, this example brings us to better understand what I'm trying to do

needless to say that XML is written like

<tipo>Colonnina</tipo>

and I'm already using this method to extrapolate data from the xml such as this without any problem

cell.textLabel.text = [NSString stringWithFormat:@"%@", [[colonninaElencoFeed objectAtIndex:indexPath.row]objectForKey:@"title"]];

I hope you can help me, thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

§对你不离不弃 2024-11-11 13:01:03

您尝试过使用 NSString isEqualToString: 吗?

if ([[[colonninaElencoFeed objectAtIndex:indexPath.row]objectAtIndex:@"tipo"] isEqualToString:@"Colonnina"] ){
do something ...
}

http://开发人员。 apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

have you tried something with NSString isEqualToString:?

if ([[[colonninaElencoFeed objectAtIndex:indexPath.row]objectAtIndex:@"tipo"] isEqualToString:@"Colonnina"] ){
do something ...
}

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

迷路的信 2024-11-11 13:01:03
if ([
       [colonninaElencoFeed objectAtIndex:indexPath.row]
             objectForKey:@"tipo"]
                   isEqualToString: @"Colonnina"] 
    ]){
       do something ...
  }
if ([
       [colonninaElencoFeed objectAtIndex:indexPath.row]
             objectForKey:@"tipo"]
                   isEqualToString: @"Colonnina"] 
    ]){
       do something ...
  }
爱冒险 2024-11-11 13:01:03

比较字符串时,您应该使用 isEqualToString 方法。您的比较应该如下所示:

if ([[[colonninaElencoFeed objectAtIndex:indexPath.row]objectAtIndex:@"tipo"] isEqualToString:@"Colonnina"] ) {
do something ...
}

When comparing strings you should use isEqualToString method. Your comparison should look like this:

if ([[[colonninaElencoFeed objectAtIndex:indexPath.row]objectAtIndex:@"tipo"] isEqualToString:@"Colonnina"] ) {
do something ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文