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? 回答1: You could try NSString *modifiedString = [yourString stringByReplacingOccurrencesOfString:@"#" withString:@""]; 回答2: stringByTrimmingCharactersInSet removes characters from the beginning and end of your string, not from any place in it For your purpose use