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).

1

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

4 Comments

I'm receiving something like : System.out.println("TEXT"); and need to convert it to the readable form.
@Sergiu Then use the second method. For a single character, the first method is better, but the second one suits better in your case.
You mean something like: var dummy = document.createElement('System.out.println("TEXT")); etc ? This does not work since it complains on invalid characters.
@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: jsfiddle.net/LGU48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.