我有一个 NSString 数组。
exampleArray = @[@"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20"];
假设你有..
NSString *exampleString = @"7";
我想在 exampleArray 中找到 exampleString,并让它返回 2 的索引,即 @"7"所在的索引。
除了遍历和比较 isEqualToString 之外,最好的方法是什么?
最佳答案
if([exampleArray containsObject:exampleString]) {
int index = [exampleArray indexOfObject: exampleString];
} else {
NSLog(@"not found");
}
关于objective-c - 查找与特定字符串匹配的 NSString NSArray 的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26292442/