Is there a way to HTML encode a string (NSString) in Objective-C, something along the lines of Server.HtmlEncode in .NET?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
the samets's routine forgot the hex digit. Here's the routine I came up with that works:
I put together a quick example project using Mike and Tod's answers here.
Makes the encoding/unencoding dead simple:
This easiest solution is to create a category as below:
Here’s the category’s header file:
And here’s the implementation:
And now we can simply do this:
The credits for this answer goes to the website below:-
I took Mike's work and turn it into a category for NSMutableString and NSString
Make a Category for NSMutableString with:
Make a Category for NSString with:
* A Swift 2.0 Version *
The Objective-C version is a little more efficient as it does mutable operations on the string. However, this is a swift way to do simple escaping:
I could have used the NSString bridging capabilities to write something very similar to the NSString version, but I decided to do it more swifty.
Use the message in the example below :
This converts 'new line' command to corresponding html code. But to convert symbols, you have to write the corresponding html number. You can see the complete list of html numbers here at
http://www.ascii.cl/htmlcodes.htm
I found the only way that uses only built-in functions (not manual parsing) and covers all cases. Requires AppKit/UIKit in addition to Foundation. This is Swift but can easily be Objective-C: