C# 文件.ReadAllText 编码.Utf8

Ahm*_*çal 0 .net c# encoding character

我尝试从 HTML 文件中读取字符串。\n这是我的代码:

\n
string result = File.ReadAllText(@"C:\\temp\\invoice.html", Encoding.UTF8);\n
Run Code Online (Sandbox Code Playgroud)\n

由于html文件的字符集是charset=windows124,所以结果值不是utf-8

\n

结果值包含;

\n
 \xef\xbf\xbd</span><br>BAH\xef\xbf\xbdEL\xef\xbf\xbdEVLER<span>\n
Run Code Online (Sandbox Code Playgroud)\n

Kja*_*tan 5

根据您的个人资料下指定的位置,我假设您的意思是windows-1254(土耳其)?

尝试:

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

有关参考,请参阅以下编码列表: https: //learn.microsoft.com/en-us/dotnet/api/system.text.encoding? view=net-6.0