Reputation: 14834
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:@""];
Upvotes: 1
Views: 1609
Reputation: 57179
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];
Upvotes: 3