You can add this extension to convert your html code to a regular string:
2017-01-16 10:55
567 查看
extension String { var html2AttributedString: NSAttributedString? { guard let data = data(using: .utf8) else { return nil } do { return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil) } catch let error as NSError { print(error.localizedDescription) return nil } } var html2String: String { return html2AttributedString?.string ?? "" } }
相关文章推荐
- when the preview menu is diabled in BO, you can add this setting to enabled it
- openshift:Perhaps your account does not have write access to this directory? You can change the cac
- 15 Things You Can Do Right Now To Help Your Career
- How to add HTML code to the clipboard by using Visual Basic Or VBA
- Convert BBCode to HTML
- 解决 Subversion 的 “svn: Can't convert string from 'UTF-8' to native encoding” 错误
- 5种提高认知潜能的方法(You can increase your intelligence: 5 ways to maximize your cognitive potential )
- VS2005,Did you forget to add '#include "stdafx.h"' to your source?
- Write Code as If You Had to Support It for the Rest of Your Life
- 故障解决:Failure adding assembly to the cache: Access denied. You might not have administrative credentials to perform this task. Contact your system administrator for assistance.
- The target assembly contains no service types. You may need to adjust the Code Access Security policy of this assembly." 目标程序集不包含服务类型。可能需要调整此程序集的代码访问安全策略。
- 15 Things You Can Do Right Now To Help Your Career
- ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings
- This event supports the .NET Framework infrastructure and is not intended to be used directly from your code?继承自VScrollbar的自定义winform控件,某些事件不触发的问题(Winform控件开发学习)
- The call to LoadLibrary(YourExtensionName) failed, Win32 error 0n14001, “This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.”
- 访问 apache 显示 Forbidden You don't have permission to access /index.html on this server. 解决方法
- 解决 Subversion 的 “svn: Can't convert string from 'UTF-8' to native encoding” 错误
- [Resolved] TF254006: No usable accounts are present in your configuration database. Use TfsConfig accounts /add to add an account and return to this wizard.
- svn: Can't convert string from 'UTF-8' to native encoding 的解决办法
- 5种提高认知潜能的方法(You can increase your intelligence: 5 ways to maximize your cognitive potential )