【发布时间】:2010-06-29 08:26:55
【问题描述】:
我只想用空白的“”字符替换所有出现的“+”... 我尝试了这里列出的一些示例,也使用了 NSSMutableString,但是程序崩溃了...... 替换另一个字符的最佳方法是什么? 谢谢
【问题讨论】:
标签: iphone nsstring str-replace nsmutablestring
我只想用空白的“”字符替换所有出现的“+”... 我尝试了这里列出的一些示例,也使用了 NSSMutableString,但是程序崩溃了...... 替换另一个字符的最佳方法是什么? 谢谢
【问题讨论】:
标签: iphone nsstring str-replace nsmutablestring
如果你想用可变字符串(NSMutableString)就地替换:
[theMutableString replaceOccurrencesOfString:@"+"
withString:@" "
options:0
range:NSMakeRange(0, [theMutableString length])]
如果你想创建一个新的不可变字符串(NSString):
NSString* newString = [theString stringByReplacingOccurrencesOfString:@"+"
withString:@" "];
【讨论】:
NSString *firstString = @"I'm a noob at Objective-C", *finalString;
finalString = [[firstString stringByReplacingOccurrencesOfString:@"O" withString:@"0"] stringByReplacingOccurrencesOfString:@"o" withString:@"0"];
从here获取代码!
【讨论】: