remove specific characters from NSString

15,871

Solution 1

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

Solution 2

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);
Share:
15,871

Related videos on Youtube

QueueOverFlow
Author by

QueueOverFlow

I am a Iphone Application Developer and I Love my work :)

Updated on September 16, 2022

Comments

  • QueueOverFlow
    QueueOverFlow over 1 year

    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.