objective-cstringnsstringnscharacterset

stringByTrimmingCharactersInSet: is not removing characters in the middle of the string


I want to remove "#" from my string.

I have tried

 NSString *abc = [@"A#BCD#D" stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"#"]];

But it still shows the string as "A#BCD#D"

What could be wrong?


Solution

  • You could try

    NSString *modifiedString = [yourString stringByReplacingOccurrencesOfString:@"#" withString:@""];