Skip to content
 
 

Latest commit

 

History

10 提交

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

仓库 files navigation

StringExtensionHTML

CI Status Version License Platform

Usage

This string extension provides two main methods, stringByDecodingHTMLEntities and stringByStrippingHTML标签.

import StringExtensionHTML

var text = ""some html string with entities ""
let decodedText = text.stringByDecodingHTMLEntities

var text = "<span><p>Some text full of <i>unwanted</i> html tags</p></span>
let decodedText = text.stringByStrippingHTML标签

Sample Project

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

StringExtensionHTML is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "StringExtensionHTML"

Alternatively, copy StringExtensionHTML.swift and add that single file into your Swift project. If you use this method, you can omit the line "import StringExtensionHTML" at the top of your file.

Credits

Original solution and former adaptations credit to Michael Waterfall and Martin from the Stack Overflow thread How do I decode HTML entities in swift?. I upgraded to work with Swift 2.0 and made it available through CocoaPods.

Note: there is a Swift 2 version by Santiago in the original thread's comments. However, while that version will compile, it will not handle numeric character entities properly and also has some flaws which will cause it to crash anytime it comes to an entity it doesn't understand.

Author

Adela Chang, a.bar.of.soap@gmail.com

License

StringExtensionHTML is available under the MIT license. See the LICENSE file for more info.

关于

No description, website, or topics provided.

Resources

Stars

1 star

关注者

3 watching

复刻s

发布

贡献者

Languages