Swift Replace Multiple Characters in String

后端 未结 4 519
日久生厌
日久生厌 2021-02-05 13:07

Below is the following line of code I use to replace an HTML break tag with a carriage return. However, I have other HTML symbols that I need to replace and when I call this lin

4条回答
  •  鱼传尺愫
    2021-02-05 13:47

    extension String {
        var html2AttributedString:NSAttributedString {
            return NSAttributedString(data: dataUsingEncoding(NSUTF8StringEncoding)!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding], documentAttributes: nil, error: nil)!
        }
    }
    
    let myHtmlCode = "Red GreenBlue"
    
    myHtmlCode.html2AttributedString
    

提交回复
热议问题