//去除字符串内的相邻的重复字符,例如:aabdaaadesff,最后结果abdadesf
NSMutableString *string = [NSMutableString stringWithFormat:@"aabbssddffiieeoo"];
NSString *strIndex1 = @"";
NSString *strIndex2 = @"";
for (NSInteger i = 0; i <= [string length]; i++) {
strIndex1 = [string substringWithRange:NSMakeRange(i, 1)];
strIndex2 = [string substringWithRange:NSMakeRange(i + 1, 1)];
if ([strIndex1 isEqualTo:strIndex2]) {
[string deleteCharactersInRange:NSMakeRange(i + 1, 1)];
}
}
NSLog(@"%@", string);
}
运行出来有错误 希望大神帮看看