简体   繁体   English

C# File.ReadAllText Encoding.Utf8

[英]C# File.ReadAllText Encoding.Utf8

I try to read string from a HTML file.我尝试从 HTML 文件中读取字符串。 Here is my code:这是我的代码:

string result = File.ReadAllText(@"C:\temp\invoice.html", Encoding.UTF8);

Since the character set of the html file is charset=windows124, the result value does not come as utf-8由于html文件的字符集是charset=windows124,所以结果值不是utf-8

The result value contains;结果值包含;

 �</span><br>BAH�EL�EVLER<span>

Based on the location specified under your profile, I assume you mean windows-1254 (Turkish)?根据您的个人资料下指定的位置,我假设您的意思是windows-1254 (土耳其语)?

Try:尝试:

Encoding turkishEncoding = Encoding.GetEncoding("windows-1254");
string result = File.ReadAllText(@"C:\temp\invoice.html", turkishEncoding);

For reference, see the encodings-list under: https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding?view=net-6.0如需参考,请参阅以下编码列表: https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding?view=net-6.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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