Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove specific characters from NSString

I wants to remove specific characters or group substring from NSString.

mean

NSString *str = @" hello I am #39;doing Parsing So $#39;I get many symbols in &my response";

I wants remove #39; and $#39; and & (Mostly these three strings comes in response)

output should be : hello I am doing Parsing So i get many symbols in my response

Side Question : I can't write & #39; without space here, because it converted in ' <-- this symbol. so i use $ in place of & in my question.

like image 836
QueueOverFlow Avatar asked Sep 28 '12 10:09

QueueOverFlow


2 Answers

you should use [str stringByReplacingOccurrencesOfString:@"#39" withString:@""] or you need replace strings of concrete format like "#number"?

like image 67
BergP Avatar answered Oct 15 '22 04:10

BergP


try below code ,i think you got whatever you want simply change the charecterset,

NSString *string = @"hello I am #39;doing Parsing So $#39;I get many symbols in &my response";
NSCharacterSet *trim = [NSCharacterSet characterSetWithCharactersInString:@"#39;$&"];
NSString *result = [[string componentsSeparatedByCharactersInSet:trim] componentsJoinedByString:@""];
NSLog(@"%@", result);
like image 23
Balu Avatar answered Oct 15 '22 04:10

Balu