iphone - Objective C 单一特定字符串替换方法

标签 iphone objective-c xcode string

我想知道是否有一种方法或方式可以帮助我替换特定字符的字符串。

喜欢 MALE - M 女-F child - P

更长的出路是这个..

[str stringByreplacingOccurencesOfString:@"MALE" withString:@"M"];
[str stringByreplacingOccurencesOfString:@"FEMALE" withString:@"F"];
[str stringByreplacingOccurencesOfString:@"CHILD" withString:@"P"];

我想知道是否有另一种方法可以减少这里的代码行,特别是当有很多东西需要替换时。

谢谢。

这是针对 iPhone 操作系统的。

最佳答案

不,但编写一个需要数组或可变参数的方法应该不会超过 5-10 分钟。

关于iphone - Objective C 单一特定字符串替换方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2656677/

相关文章:

iphone - 在 iOS 6 中使用特定帐户发推文?

ios - 如何设置 UISegmentedControl 框架?

ios - 在 iphone 中单击按钮时如何将文本字段/标签中的值添加到数组

SwiftUI 获取 ViewModel 中另一个 ViewModel 的值

iPhone 开发者 : any snippet to resize an image and keep the ratio?

iPhone:设置一个应用程序以用作 "In App Purchase"

iphone - 类型转换花车和 UILabel

objective-c - 无法将 QuickTime 影片 View 添加到 Cocoa 应用程序

iphone - UITextField 文本未出现在中心

ios - 从 TableView 中选择一行后如何更改按钮图像 - iOS