Objective-C中的字符串替换 [英] String replacement in Objective-C
本文介绍了Objective-C中的字符串替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
替换字符的最佳方法是使用Objective-C for iPhone SDK中的字符串?
What is the best way to replace a character is a string in Objective-C for iPhone SDK?
推荐答案
你可以使用方法
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target
withString:(NSString *)replacement
...获取一个替换了子串的新字符串(参见 NSString
其他人的文件)
...to get a new string with a substring replaced (See NSString
documentation for others)
使用示例
NSString *str = @"This is a string";
str = [str stringByReplacingOccurrencesOfString:@"string"
withString:@"duck"];
这篇关于Objective-C中的字符串替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文