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?
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?
I wrote a category of
NSString
for that:You can use it like this:
stringByTrimmingCharactersInSet
removes characters from the beginning and end of your string, not from any place in itFor your purpose use
stringByReplacingOccurrencesOfString:withString:
method as others pointed.Use below
You could try
I previously had a relatively complicated recursive answer for this (see edit history of this answer if you'd like to see that answer), but then I found a pretty simple one liner:
Refer to the Apple Documentation about: stringByReplacingOccurrencesOfString: method in NSString
Hope this helps.