首页 > 移动平台 > 详细

iOS 数组中查找字符串

时间:2015-04-11 01:10:12      阅读:388      评论:0      收藏:0      [点我收藏+]
NSArray *helloWorld = @[@"world",@"hello"];
NSString *hello_Constant = @"hello";
NSString *helloFormate1  =[NSString stringWithFormat:@"%@llo",@"he"];
    
NSInteger indexConstant  = [helloWorld indexOfObject:hello_Constant];
NSInteger indexFormate1  = [helloWorld indexOfObject:helloFormate1];
hello_Constant及helloFormate1的字符串相同,地址不同

技术分享

神奇的是两者在数组中的index竟然是相同的

技术分享

这就说明数组中的对象并不只是比较的对象的地址,还判断了字符串是否相等

以后在数组中寻找某个字符串 不需要再遍历数组 再调用 isEqualToString 方法啦 :)

iOS 数组中查找字符串

原文:http://www.cnblogs.com/binglin92/p/4415998.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!