manually exclude some symbols from [NSCharacterSet letterCharacterSet] invertedSet]
The code below will remove all symbols from myString. Is there a shortest way to make some exclusive symbols (say ')from being removed while still be able to use this code?
myString = [[myString componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] componentsJoinedByString:@开发者_如何转开发""];
You will need to create a mutable copy and then make changes using the NSMutableCharacterSet
.
NSMutableCharacterSet *mcs = [[[NSCharacterSet letterCharacterSet] invertedSet] mutableCopy];
[mcs removeCharactersInString:@"<characters you want excluded>"];
myString = [[myString componentsSeparatedByCharactersInSet:mcs] componentsJoinedByString:@""];
[mcs release];
精彩评论