I have a string and I need to encode it in html. For example ">" becomes "& gt;" In C# I do
string stringEncoded = System.Net.HttpUtility.HtmlEncode(myString);
How can I do the same thing in Swift?
I have a string and I need to encode it in html. For example ">" becomes "& gt;" In C# I do
string stringEncoded = System.Net.HttpUtility.HtmlEncode(myString);
How can I do the same thing in Swift?
Might be extremely late by now... At the moment I am doing it like this
let html = "<pre>something</pre>"
var result = html.stringByReplacingOccurrencesOfString("&", withString: "&", options: nil, range: nil)
result = result.stringByReplacingOccurrencesOfString("\"", withString: """, options: nil, range: nil)
result = result.stringByReplacingOccurrencesOfString("'", withString: "'", options: nil, range: nil)
result = result.stringByReplacingOccurrencesOfString("<", withString: "<", options: nil, range: nil)
result = result.stringByReplacingOccurrencesOfString(">", withString: ">", options: nil, range: nil)
print(result)