NSMutableAttributedString

NSMutableAttributedString

这适用于常规 NSString :

NSString *newString = [myString stringByReplacingOccurrencesOfString:@"," withString:@""];

但是 NSMutableAttributedString 没有这样的方法。如何删除 NSMutableAttributedString 中逗号的所有实例?

最佳答案

let attrString = NSMutableAttributedString(string: "Hello <b>friend<b>")

attrString.mutableString.replaceOccurrencesOfString("<b>", withString: "", options: NSStringCompareOptions.CaseInsensitiveSearch, range: NSRange(location: 0, length: attrString.length))

试试这个 :)

关于ios - 替换 NSMutableAttributedString 中的字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29635950/

10-11 14:24