6

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.

4

2 回答 2

14

您应该使用[str stringByReplacingOccurrencesOfString:@"#39" withString:@""] 还是需要替换具体格式的字符串,例如“#number”?

于 2012-09-28T10:10:02.700 回答
13

试试下面的代码,我想你得到了你想要的任何东西,只需改变字符集,

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);
于 2012-09-28T10:34:43.693 回答