NSRange searchRange = [myString rangeOfString:@"five"];
if (searchRange.location != NSNotFound)
// 搜索指定字符的确切位置及长度 searchRange.location, searchRange.length
NSLog(@"Range location:%d, length:%d", searchRange.location, searchRange.length);
// 替换指定字符串,也可替换空格,逗号等
NSLog(@"替换后:%@", [myString stringByReplacingCharactersInRange:searchRange
withString:@"New string"]);
// 替换所有匹配项
NSString *replaced = [myString stringByReplacingOccurrencesOfString:@" " withString:@"*"];
NSLog(@"%@", replaced);
2013-05-17 10:59:41.817 base 5-14[597:c07] Range location:19, length:4
2013-05-17 10:59:41.817 base 5-14[597:c07] 替换后:one two three four New string six seven
2013-05-17 10:59:41.818 base 5-14[597:c07] one*two*three*four*five*six*seven