Tuesday 15 June 2010

Decode mixed ASCII codes from a string in JavaScript -


I have a JavaScript code that removes the JSON string from other pages of my blog (blogger), but many of them Special character strings & amp; #include in the form of where is a number up to 5 digits, or as is something like \ 74br / \ 76 , which should be .

Both are mixed in the same string, and both are ASCII, the first is a decimal / html and the second is octal.

How can I understand this mess about their respective characters using Javascript? Is there an existing function or a suitable solution for it?

You should start

  function decodeHtmlNumeric (str) { Return str.replace (/ & ([0-9] {1,7}); / g, function (g, m1) {return String.fromCharCode (parseInt (M1, 10))}} (/ & Amp; # [xX] ([0- 9A-FA-F] {1,6}) / g, function (g, m1) {return string.framecod (parseint (m1, 16)) ;}); } Function decodeOctal (str) {return str.replace (/ \\ ([0-7] +) / g, function (g, m1) {return string. Lightcard (purseint (m1, 8))}) ; } // double \\ = a backslash decode-optical ("\\ 74br / \\ 76"); // "
" DecodeHtmlNumeric ("& # 255;"); // "ÿ"

No comments:

Post a Comment