确定文本文件编码架构 [英] Determining text file encoding schema
本文介绍了确定文本文件编码架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一种可以检测文本文件编码模式的方法.我知道那里有很多,但是我确定我的文本文件是 ASCII
, UTF-8
或 UTF-16
.我只需要检测这三个即可.有人知道这样做的方法吗?
I am trying to create a method that can detect the encoding schema of a text file. I know there are many out there, but I know for sure my text file with be either ASCII
, UTF-8
, or UTF-16
. I only need to detect these three. Anyone know a way to do this?
推荐答案
使用StreamReader识别编码.
Use the StreamReader to identify the encoding.
示例:
using(var r = new StreamReader(filename, Encoding.Default))
{
richtextBox1.Text = r.ReadToEnd();
var encoding = r.CurrentEncoding;
}
这篇关于确定文本文件编码架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文