iOS 数组中查找字符串

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 方法啦 :)

posted on 2015-04-10 23:55  永远的冰蝴蝶  阅读(2082)  评论(0)    收藏  举报

导航