Converting & to & in Objective-C [duplicate]

Check out my NSString category for HTML. Here are the methods available: // Strips HTML tags & comments, removes extra whitespace and decodes HTML character entities. – (NSString *)stringByConvertingHTMLToPlainText; // Decode all HTML entities using GTM. – (NSString *)stringByDecodingHTMLEntities; // Encode all HTML entities using GTM. – (NSString *)stringByEncodingHTMLEntities; // Minimal unicode encoding will only … Read more

Replacing   from javascript dom text node

This is much easier than you’re making it. The text node will not have the literal string “ ” in it, it’ll have have the corresponding character with code 160. function replaceNbsps(str) { var re = new RegExp(String.fromCharCode(160), “g”); return str.replace(re, ” “); } textNode.nodeValue = replaceNbsps(textNode.nodeValue); UPDATE Even easier: textNode.nodeValue = textNode.nodeValue.replace(/\u00a0/g, ” “);

When should one use HTML entities?

Based on the comments I have received, I looked into this a little further. It seems that currently the best practice is to forgo using HTML entities and use the actual UTF-8 character instead. The reasons listed are as follows: UTF-8 encodings are easier to read and edit for those who understand what the character … Read more

How to convert characters to HTML entities using plain JavaScript

With the help of bucabay and the advice to create my own function i created this one which works for me. What do you guys think, is there a better solution somewhere? if(typeof escapeHtmlEntities == ‘undefined’) { escapeHtmlEntities = function (text) { return text.replace(/[\u00A0-\u2666<>\&]/g, function(c) { return ‘&’ + (escapeHtmlEntities.entityTable[c.charCodeAt(0)] || ‘#’+c.charCodeAt(0)) + ‘;’; }); … Read more