2016-08-13 84 views
-1

给定一个非Unicode文本的txt文件,我能够检测到它的字符集为。现在,我想转换成unicode。非Unicode到Unicode文本转换的一个TXT文件

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

这不起作用。

难道这就是这样吗非unicode转换为unicode

在尝试了RTF文件上的建议方法后,当我尝试打开输出RTF文件时,出现下面的对话框。请让我知道该怎么办,因为选择Unicode不会使其可读或提供预期的文本?

enter image description here

回答

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

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

谢谢您的及时回复!当我用RTF文件尝试你的代码时,我得到了附加的对话框。还有什么我需要做的吗? – John

+1

@Holly - rtf([富文本格式](https://en.wikipedia.org/wiki/Rich_Text_Format))不是txt(纯文本)。你真的想做什么? –

+0

@霍利:你还应该说什么是创建对话框 - 我们不知道什么应用程序试图打开文件。 –