如何从字符串中删除特定符号? [英] how to remove a particular sign from a string?

查看:80
本文介绍了如何从字符串中删除特定符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串

gpbusd〜buy ~~~~更新〜HIT 40点〜HIT 110点~~ gpbusd〜buy ~~~ BREAK偶〜更新〜HIT〜100 + ~~ gpbusd〜buy〜1.5500/25〜1.5455~~ new〜40〜100 + ~~ gpbusd〜buy ~~~~更新〜关闭0至10点N ~~~ gpbusd〜buy〜1.5335/50〜1.5320 ~~ new〜40〜80 + ~~ gpbusd〜buy~~~~更新~~ 15-20点关闭〜保持打开〜gpbusd〜购买〜1.5530/50 ~~ 1.5505〜更新〜HIT〜80〜保持打开〜gpbusd〜购买〜1.5530/50〜1.5465 ~~新〜40〜80〜100 +〜gbpjpy〜卖〜131.05/.130.75〜132.15 ~~新〜60〜100〜开价〜欧元〜卖〜1.2840/20〜1.2870〜STOP〜更新~~~~

我要删除分隔符并分隔它们之间的所有单词?我该怎么办?

解决方案

  • 分割字符串:

      NSArray * parts = [string componentsSeparatedByString:@〜"]; 

  • 从数组中组装一个字符串:

      NSString * string = [parts componentsJoinedByString:@"]; 

  • 通过使用空格替换所有出现在中的字符串来对字符串进行消毒:

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

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?

解决方案

  • 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:@" " ]
    

这篇关于如何从字符串中删除特定符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆