排除" @"来自punctuationCharacterSet的标志

时间:2014-06-07 13:12:01

标签: nsrange nscharacterset

我正在尝试使用此代码以这种方式过滤我的attributionString。但是,我希望rangeOfCharacterFromSet:包含" @"的所有原始值除外。标志。我该怎么做?

NSRange rangeSpace = [filteredText rangeOfCharacterFromSet:[NSCharacterSet punctuationCharacterSet] options:NSCaseInsensitiveSearch range:NSMakeRange(range.location, filteredText.length - range.location)];

1 个答案:

答案 0 :(得分:1)

NSMutableCharacterSet *punctuationSet = [NSMutableCharacterSet punctuationCharacterSet];
[punctuationSet removeCharactersInString:@"@"];

NSRange searchRange = NSMakeRange(range.location, filteredText.length - range.location)

NSRange rangeSpace = [filteredText rangeOfCharacterFromSet:punctuationSet 
                                                   options:NSCaseInsensitiveSearch
                                                     range:searchRange];