How to convert escaped Unicode (e.g. \\u0432\\u044

2019-06-16 11:26发布

问题:

I have .properties files with a bunch of unicode escaped characters. I want to convert it to the correct chars display.

E.g.:

Currently: \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\u005c
Desired result: все готово

Notepad++ is already set to encode UTF8 without BOM. Opening the document and 'converting' (from the Encoding drop-down menu) doesn't do anything.

How do I achieve this with notepad++?

If not in Notepad++, is there any other way to do this for many files, perhaps by using some script?

回答1:

You need a plugin named HTML Tag. Once plugin is installed, select your text and invoke command Plugins > HTML Tag > Decode JS (Ctrl+Shift+J).



回答2:

I'm not aware of how you can do it natively in Notepad++ but as requested you can script it with Python:

import codecs

# opens a file and converts input to true Unicode
with codecs.open("escaped-unicode.txt", "rb", "unicode_escape") as my_input:
    contents = my_input.read()
    # type(contents) = unicode 

# opens a file with UTF-8 encoding
with codecs.open("utf8-out.txt", "wb", "utf8") as my_output:
    my_output.write(contents)