0

Is there anything embedded in javascript that decodes an entry like " to " ?

I would need something similar to what is found here: http://www.hashemian.com/tools/html-url-encode-decode.php (the decimal decode).

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sergiu
  • 2,502
  • 6
  • 35
  • 57

1 Answers1

4

Use the String.fromCharCode method. Example:

var entity = '"';
var numeric = /\d+/.exec(entity);
var decoded = String.fromCharCode(numeric);

A general HTML entity-to-character method is:

var dummy = document.createElement('textarea');
dummy.innerHTML = entity;
var decoded = dummy.value;
Community
  • 1
  • 1
Rob W
  • 341,306
  • 83
  • 791
  • 678
  • I'm receiving something like : System.out.println("TEXT"); and need to convert it to the readable form. – Sergiu Apr 04 '12 at 11:40
  • @Sergiu Then use the second method. For a single character, the first method is better, but the second one suits better in your case. – Rob W Apr 04 '12 at 11:42
  • You mean something like: var dummy = document.createElement('System.out.println("TEXT")); etc ? This does not work since it complains on invalid characters. – Sergiu Apr 04 '12 at 11:47
  • @Sergiu 1. `document.createElement` should be sticked to the **`textarea`** string. 2. You're missing the closing single quote on your string. Here's a working demo for your given string: http://jsfiddle.net/LGU48/ – Rob W Apr 04 '12 at 15:36