ios:用返回值替换NSString中的单词

时间:2013-06-27 01:52:21

标签: ios replace nsstring

我有以下NSString:

"This is a test String
*This a test string"

我想用这样的回报替换“*”

"This is a test string

This is a test string"

我试过了:

[removeStr stringByReplacingOccurrencesOfString:@"*" withString:@"/r"];

但它打印“/ r”,当我尝试“\ r”时,我得到一个lldb错误

任何帮助?

1 个答案:

答案 0 :(得分:2)

NSString *str = @"This is a test String*This a test string";
NSString *str2 = [str stringByReplacingOccurrencesOfString:@"*" withString:@"\n"];
NSLog(@"%@", str2);

如果字符串如此,则替换\n,结果为:

This is a test String
This a test string