【问题标题】:How to remove space/blank between any two words using RegexKitLite?如何使用 RegexKitLite 删除任意两个单词之间的空格/空格?
【发布时间】:2010-12-23 00:05:35
【问题描述】:

我想删除任意两个单词之间的空格并添加我想要的任何内容。例如,我将有一个字符串,其中包含两个单词,两个单词之间有一个空格。我希望能够删除空间并用我声明的东西替换空间。另外,这需要用objective-c或c编写。

NSString *string = @"Word Word2";

我需要一个表达式来执行此操作,但我似乎无法掌握 RegexKitLite。任何帮助,将不胜感激。谢谢

【问题讨论】:

    标签: iphone objective-c c regex xcode


    【解决方案1】:

    使用NSStringstringByReplacingOccurrencesOfString:withString:方法:

    NSString *spaceReplacement = @"whatever";
    NSString *replaced = [string stringByReplacingOccurrencesOfString:@" " withString:spaceReplacement];
    

    【讨论】: