I want to remove all special character except +, space and – . How it is possible?
My string is
Äî;a[bRa]Co-Founder MobÄ: +91 9711700008
output:
abRaCo-Founder Mob +91 9711700008
According to Answer below, I update my code but still no success.
NSMutableCharacterSet *special = [NSMutableCharacterSet characterSetWithCharactersInString:@"+ -"];
[special formUnionWithCharacterSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]];
NSString *temp=@"gaurav 1!@#!#@! kant !@#!@#!@#12kestwal ";
NSString *yourString = [temp stringByTrimmingCharactersInSet:special];
NSLog(@"%@",yourString);
I missing anything?
This is an example of how to achieve what you’re trying to do:
The isWanted function returns YES if you want to have that character in string.For legibility I didn’t use a lot of logic OR’s but just if’s, you can replace that with an unique if.
Sometimes if watching the documentation takes too much time, you can invent the solution yourself.Many people will disagree, of course a solution with a single line is better, but if you don’t find the right documented method why losing time?