nth を見つけたら、何をしたいです@
か?
ソリューションをスケッチするサンプル コードを次に示します。コンパイルもバグチェックもされていません!
int targetItem = 3; // we find the 3rd item
NSString *workingStr = @"your@string@containing@stuff";
int foundAtLocation = -1;
for (int idx = 0; idx < targetItem; idx++) {
NSRange range = [workingStr rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"@"]];
if (range.location < 0) {
// not found, give up
foundAtLocation = -1;
break;
}
workingStr = [workingStr substringFromIndex:range.location];
foundAtLocation += range.location;
}
if (foundAtLocation >= 0) {
NSLog(@" I found the %d occurence of @ at character index %d", targetItem, foundAtLocation);
}
else {
NSLog(@" Not found");
}