简体   繁体   中英

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.

你应该使用[str stringByReplacingOccurrencesOfString:@"#39" withString:@""]或者你需要替换像“#number”这样的具体格式的字符串?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM