Exclude "@" sign from punctuationCharacterSet

511 views Asked by At

I am trying to filter my attributedString this way, using this code. However, I want the rangeOfCharacterFromSet: to include all of its original values EXCEPT for the "@" sign. How would I do this?

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

There are 1 answers

0
Sulthan On BEST ANSWER
NSMutableCharacterSet *punctuationSet = [NSMutableCharacterSet punctuationCharacterSet];
[punctuationSet removeCharactersInString:@"@"];

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

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