iOS 数组中查找字符串

时间:2015-04-11 01:10:12   收藏:0   阅读:389
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 方法啦 :)

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!