Csharp/C#教程:C#中的自动编码检测分享


C#中的自动编码检测

可能重复:
在C#中确定字符串的编码

许多文本编辑器(如Notepad ++)可以检测任意文件的编码。 我可以在C#中检测到文件的编码吗?

如果在尝试读取时有BOM, StreamReader将尝试自动检测文件的编码:

上述就是C#学习教程:C#中的自动编码检测分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

public class Program { static void Main(string[] args) { using (var reader = new StreamReader("foo.txt")) { // Make sure you read from the file or it won't be able // to guess the encoding var file = reader.ReadToEnd(); Console.WriteLine(reader.CurrentEncoding); } } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1004182.html

(0)
上一篇 2021年12月29日
下一篇 2021年12月29日

精彩推荐