NSString 特殊字符

/*
 函数描述:字符串筛选,去掉不需要的特殊字符串
 参数描述:target         原字符串
         replacement   需要替换的字符串
         options       默认传2:NSLiteralSearch,区分大小写
         _replaceArray 需要排除的Array
 返回值: 筛选完的String
 备注:   使用方法:replaceOccurrencesOfString:@"1(2*3" withString:@"" options:2 replaceArray:[NSArray arrayWithObjects:@"(",@"*", nil]
 输出:123
 */
+ (NSString *)replaceOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)options replaceArray:(NSArray *)_replaceArray {
    NSMutableString *tempStr = [NSMutableString stringWithString:target];
    NSArray *replaceArray = [NSArray arrayWithArray:_replaceArray];
    for(int i = 0; i < [replaceArray count]; i++){
        NSRange range = [target rangeOfString: [replaceArray objectAtIndex:i]];
        if(range.location != NSNotFound){
            [tempStr replaceOccurrencesOfString: [replaceArray objectAtIndex:i]
                                     withString: replacement
                                        options: options
                                          range: NSMakeRange(0, [tempStr length])];
        }
    }
    return tempStr;
}

日志地址:http://www.cnblogs.com/maxfong/archive/2013/01/28/2880672.html

posted @ 2013-01-28 22:53  Maxfong  阅读(2132)  评论(1编辑  收藏  举报