1
$\begingroup$

I'm using Mathematica v10.0.2 on Win7.

I have a text file in which there are some Chinese characters and I would Import the file into Mathematica as a string by:

str=Import["...file.txt"]

However, the Chinese characters were all "translated" to strange characters like "Ò»Êø¹â".

Note that a string containing Chinese characters can be correctly Export ed to a txt file.

nothing changes when I try $CharacterEncoding = "UTF-8" or $SystemCharacterEncoding = "UTF-8"

what should I do?

Or is there any I can turn the "Ò»Êø¹â" back to the characters in original txt file?

$\endgroup$
1
  • 1
    $\begingroup$ maybe you can use option CharacterEncoding -> "CP936" $\endgroup$
    – partida
    Commented Apr 8, 2016 at 7:41

1 Answer 1

3
$\begingroup$

refering to Can I read Chinese characters with ReadList correctly? here is the solution:

first try

FromCharacterCode[
ToCharacterCode[
ReadList["...file.txt", Record, 1]], #] & /@ $CharacterEncodings

read the output then select the one of $CharacterEncodings which correctly translated the characters (which may depend on your systems or Mathematica versions), inset it into the # in the code above.

for my Mma10.0.2 on Win7, It's "CP936" that works

FromCharacterCode[
ToCharacterCode[
ReadList["...file.txt", Record, 1]], "CP936"] & /@ $CharacterEncodings
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.