如何使用 RegexKitLite 删除任意两个单词之间的空格/空白? [英] How to remove space/blank between any two words using RegexKitLite?
问题描述
我想删除任意两个单词之间的空格并添加我想要的任何内容.例如,我将有一个字符串,其中包含两个单词,两个单词之间有一个空格.我希望能够删除空间并用我声明的内容替换空间.另外,这需要用objective-c或c编写.
I'm wanting to remove a space between any two words and add anything that I want. For example, I'll have a string that has two words in it with a space between the two. I want to be able to remove the space and replace the space with something that I declare. Also, this needs to be written in objective-c or c.
NSString *string = @"Word Word2";
我需要一个表达式来执行此操作,但我似乎无法掌握 RegexKitLite.任何帮助,将不胜感激.谢谢
I'm needing an expression to do this and I can't seem to grasp RegexKitLite. Any help would be appreciated. Thanks
推荐答案
使用 NSString
的 stringByReplacingOccurrencesOfString:withString:
方法:
Use NSString
's stringByReplacingOccurrencesOfString:withString:
method:
NSString *spaceReplacement = @"whatever";
NSString *replaced = [string stringByReplacingOccurrencesOfString:@" " withString:spaceReplacement];
这篇关于如何使用 RegexKitLite 删除任意两个单词之间的空格/空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!