替换 NSMutableAttributedString 中的字符 [英] Replace character in NSMutableAttributedString

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

问题描述

这适用于常规的 NSString:

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

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

But there is no such method for NSMutableAttributedString. How could I remove all instances of a comma in an NSMutableAttributedString?

推荐答案

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

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

试试这个:)

这篇关于替换 NSMutableAttributedString 中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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