Objective-C 中的字符串替换 [英] String replacement in Objective-C

查看:29
本文介绍了Objective-C 中的字符串替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C中如何替换一个字符是一个字符串?

How to replace a character is a string in Objective-C?

推荐答案

你可以使用方法

- (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆