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

前端 未结 6 2232
北荒
北荒 2020-12-15 06:23

I want to remove \"#\" from my string.

I have tried

 NSString *abc = [@\"A#BCD#D\" stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWith         


        
6条回答
  •  Happy的楠姐
    2020-12-15 06:36

    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: 

    - (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet *)characterSet {
        return [[self componentsSeparatedByCharactersInSet:characterSet] componentsJoinedByString:@""];
    }
    

提交回复
热议问题