主要方法:
- 获取子字符串:substringWithRange:
- 替换字符串:stringByReplacingCharactersInRange:range
for (int i = 0; i<[string length]; i++) {
//截取字符串中的每一个字符
NSString *s = [string substringWithRange:NSMakeRange(i, 1)];
NSLog(@"string is %@",s);
if ([s isEqualToString:@"m"]) {
NSRange range = NSMakeRange(i, 1);
//将字符串中的“m”转化为“w”
string = [string stringByReplacingCharactersInRange:range withString:@"w"];
}
}
NSLog(@"%@",string);