Double-Escaped Unicode Javascript Issue

Posted by Jeffrey Winter on Stack Overflow See other posts from Stack Overflow or by Jeffrey Winter
Published on 2008-11-08T18:17:45Z Indexed on 2010/05/09 4:38 UTC
Read the original article Hit count: 319

I am having a problem displaying a Javascript string with embedded Unicode character escape sequences (\uXXXX) where the initial "\" character is itself escaped as "\" What do I need to do to transform the string so that it properly evaluates the escape sequences and produces output with the correct Unicode character?

For example, I am dealing with input such as:

"this is a \u201ctest\u201d";

attempting to decode the "\" using a regex expression, e.g.:

var out  = text.replace('/\/g','\');

results in the output text:

"this is a \u201ctest\u201d";

that is, the Unicode escape sequences are displayed as actual escape sequences, not the double quote characters I would like.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about unicode