how to convert utf8 code to character in Julia?

Viewed 271

I am reading string from a file which is plain text with us-utf8 encodings, after reading the contents, I want to extract the file name which contains chinese character and the chinese characters are stored in the file with its utf8 code e.g.: \x6532\x6320.pdf etc.. of course I need to change it to \u instead of \x

But I got confused because in julia console, it is easy to get the corresponding chinese character when println("\u6532\u6320.pdf") or whatever, but if the string is read from the file, it can only be displayed as "\u6532\u6320.pdf" exactly as it is stored in the text file. I admit it should be the desired behavior. But how could I convert the utf8 code to the corresponding character as from the console result, I believe I have the correct $LANG setting.

I make some test in julia console as follows:

println("\u6543")    =>   敃
println("\\" * "u6543") => \u6543

basically the second line is the problem I met when I read string from my text file, also I tried to use the StringEncoding package to solve the problem as follows:

using StringEncoding
println(decode(Vector{UInt8}(replace(line_content_from_text,"\\x"=>"\\u"),"UTF-8"))

but still I got something like \u6543.

1 Answers
Related