简体   繁体   中英

Non-Unicode to unicode conversion of a txt file

Given a txt file with non-unicode text, I am able to detect its charset as 1251 . Now, I would like to convert into unicode.

byte[] bytes1251 = Encoding.GetEncoding(1251).GetBytes(File.ReadAllText("sampleNU.txt"));
String str = Encoding.UTF8.GetString(bytes1251);

This doesn't work.

Is this the way to go about it for non-unicode to unicode conversion ?

After trying the suggested approach on the RTF file, I get the below dialog when I try to open the output RTF file. Please let me know what to do because selecting Unicode doesn't make it readable or give the expected text?

在此处输入图片说明

// load as charset 1251
string text = File.ReadAllText("sampleNU.txt", Encoding.GetEncoding(1251));

// save as Unicode
File.WriteAllText("sampleU.txt", text, Encoding.Unicode);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM