how to remove a particular sign from a string?

让人想犯罪 __ 提交于 2019-12-08 12:56:41

问题


i have a string

gpbusd~buy~~~~update~HIT 40 PIPS~HIT 110 PIPS~~gpbusd~buy~~~BREAK EVEN~update~HIT~100+~~gpbusd~buy~1.5500/25~1.5455~~new~40~100+~~gpbusd~buy~~~~update~CLOSE 0 TO 10 PIPS N~~~gpbusd~buy~1.5335/50~1.5320~~new~40~80+~~gpbusd~buy~~~~update~~15-20 PIPS CLOSE~KEEP OPEN~gpbusd~buy~1.5530/50~~1.5505~update~HIT~80~KEEP OPEN~gpbusd~buy~1.5530/50~1.5465~~new~40~80~100+~gbpjpy~sell~131.05/.130.75~132.15~~new~60~100~keep open~eurusd~sell~1.2840/20~1.2870~STOP~update~~~~

i want remove the delimeter sign and separate all the words between them ?how can i do it?


回答1:


  • Splitting a string:

    NSArray *parts = [string componentsSeparatedByString: @"~"];
    
  • Assembling a string from an array:

    NSString *string = [parts componentsJoinedByString: @" "];
    
  • Sanitizing a string, by replacing all occurences of ~ with whitespace:

    NSString *string = [string stringByReplacingOccurrencesOfString: @"~"\
                               withString:@" " ]
    


来源:https://stackoverflow.com/questions/3767721/how-to-remove-a-particular-sign-from-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!