Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you can use the functions from a question on a slightly different subject (<a href="https://stackoverflow.com/questions/286921">Efficiently replace all accented characters in a string?</a>).</p> <p>Jason Bunting's answer has some nice ideas + the necessary explanation, here is his solution with some modifications to get you started (<em>if you find this helpful, upvote his original answer as well, as this is his code, essentially</em>).</p> <pre><code>var replaceHtmlEntites = (function() { var translate_re = /&amp;(nbsp|amp|quot|lt|gt);/g, translate = { 'nbsp': String.fromCharCode(160), 'amp' : '&amp;', 'quot': '"', 'lt' : '&lt;', 'gt' : '&gt;' }, translator = function($0, $1) { return translate[$1]; }; return function(s) { return s.replace(translate_re, translator); }; })(); </code></pre> <p>callable as</p> <pre><code>var stringToMatch = "This string has special chars &amp;amp; and &amp;amp;nbsp;"; var stringOutput = replaceHtmlEntites(stringToMatch); </code></pre> <p>Numbered entites are even easier, you can replace them much more generically using a little math and <a href="http://www.w3schools.com/jsref/jsref_fromCharCode.asp" rel="nofollow noreferrer"><code>String.fromCharCode()</code></a>.</p> <hr> <p>Another, much simpler possibility would be like this (works in any browser)</p> <pre><code>function replaceHtmlEntites(string) { var div = document.createElement("div"); div.innerHTML = string; return div.textContent || div.innerText; } replaceHtmlEntites("This string has special chars &amp;lt; &amp;amp; &amp;gt;"); // -&gt; "This string has special chars &lt; &amp; &gt;" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload