美文网首页
iOS 字符串去除相同元素

iOS 字符串去除相同元素

作者: ShawnJiFreeMan | 来源:发表于2019-03-16 17:58 被阅读0次
/**
去除字符串中相同的元素只保留一个
如:1121334466 - > 12346
**/
-(NSString *)removeStrxtys:(NSString *)origStr{
    NSString *temp = nil;
    NSMutableArray *arr_0 = [NSMutableArray new];
    for(int i =0; i < [origStr length]; i++)
    {
        temp = [origStr substringWithRange:NSMakeRange(i, 1)];
        BOOL isbool = [arr_0 containsObject:temp];
        if (!isbool) {
            [arr_0 addObject:temp];
        }
    }
    NSString *result = [arr_0 componentsJoinedByString:@""];
    return result;
}

相关文章

网友评论

      本文标题:iOS 字符串去除相同元素

      本文链接:https://www.haomeiwen.com/subject/hkwsmqtx.html