1

I have one Text File abc.txt which is in Unicode format. I want to convert this into ANSI format. How to do this.

I have done google and got the following , but Its very lengthy to understand.

Java- Converting from unicode to ANSI

Community
  • 1
  • 1
  • Does your "ANSI" refer to [this](http://stackoverflow.com/questions/701882/what-is-ansi-format)? Why do you want to do that? – Alvin Wong Apr 22 '13 at 10:30
  • @Alvin Wong - Thanks For Your Response. Anyway I have got one work around. I am opening the Text File using Pywinauto and Save as in ANSI formate. That is working for me. Thanks –  Apr 22 '13 at 11:03

1 Answers1

1

At a wild guess, because you're using pywinauto, it means that the data you have is in the default win32 encoding format for unicode, which is to say, in UTF-16LE. There is no such thing as a file in unicode, the file is in an encoded representation of unicode.

To convert a file from UTF-16 to ASCII,you want to do:

unicode_data = open(filename).read().decode('utf-16le')
ascii = unicode_data.decode('ascii')
Petesh
  • 82,900
  • 3
  • 91
  • 111