Unicode and URI encoding, decoding and escaping in JavaScript
- by apphacker
If you look at this table here, it has a list of escape sequences for Unicode characters that don't actually work for me.
For example for "%96", which should be a –, I get an error when trying decode:
decodeURIComponent("%96");
URIError: URI malformed
If I attempt to encode "–" I actually get:
encodeURIComponent("–");
"%E2%80%93"
I searched through the internet and I saw this page, which mentions using escape and unescape with decodeURIComponent and encodeURIComponent respectively. This doesn't seem to help because %96 doesn't show up as "–" no matter what I try and this of course wouldn't work:
decodeURIComponent(escape("%96));
"%96"
Not very helpful.
How can I get "%96" to be a "–" with JavaScript (without hardcoding a map for every single possible unicode character I may run into)?