2

I have a string like so:

var x = "as dsa sad asd      asd asd asd asd asd asd asd"

How can I decode that string to get just:

"as dsa sad asd asd asd asd asd asd asd asd"

Thanks

4
  • I'd be curious to know where the string comes from and then were it is being sent. You may not need to do any decoding depending on your use case. Commented Nov 18, 2011 at 6:57
  • Possible duplicate of Jquery decode HTML entities. Commented Nov 18, 2011 at 6:59
  • It's in a contenteditable div Commented Nov 18, 2011 at 6:59
  • var decoded = $("<div/>").html(encodedStr).text(); - stackoverflow.com/questions/1147359/jquery-decode-html-entities/… Commented Nov 18, 2011 at 7:02

1 Answer 1

4

Try this

var encoded = "as dsa sad asd &nbsp; &nbsp; &nbsp;asd asd asd asd asd asd asd";
alert(encoded);
var decoded = $('<textarea />').html(encoded).val();
alert(decoded);

or

var decoded = $("<div/>").html(encoded).text();
Sign up to request clarification or add additional context in comments.

Comments

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.