NSString *a = @"aabslcad";
NSMutableArray *temps = [NSMutableArray array];
NSString*temp =nil;
for(inti =0; i < [a length]; i++)// 遍历每个字符
{
temp = [a substringWithRange:NSMakeRange(i,1)];
[temps addObject:temp];
}
NSMutableArray *indexs = [NSMutableArray array];
NSString*t =nil;
NSString*t1 =nil;
for(inti =0; i < temps.count; i ++) {
t = temps[i];
for(intj =0; j < i; j++) {
t1 = temps[j];
//判断两个字符是否相等,切不相邻
if(t == t1 && i != j +1) {
[indexs addObject:[NSStringstringWithFormat:@"%d",i]];
}
}
}
//去重
NSSet*set = [NSSetsetWithArray:indexs];
//获取不相邻重复字符的位置
for(NSString *tem in set) {
NSIntegeridx = [temintegerValue];
[temps replaceObjectAtIndex:idx withObject:@" "];
}
NSString *ttt = [temps componentsJoinedByString:@" "];
//获得最后字符串(aabcd)
NSString *tttt = [ttt stringByReplacingOccurrencesOfString:@" " withString:@""];