2019-11-29-dotnet-core-使用-GBK-编码

title author date CreateTime categories
dotnet core 使用 GBK 编码
lindexi
2019-11-29 08:32:11 +0800
2019-8-29 9:38:8 +0800
dotnet

本文告诉大家如何在 .NET Core 中使用 GBK 编码

默认的 .NET Core 框架不包含 GBK 编码,不包含除了代码页为 28591 和 Unicode(utf-8,utf-16) 之外的其他编码,需要安装 System.Text.Encoding.CodePages 才能使用

先通过 NuGet 安装 System.Text.Encoding.CodePages 库

然后在使用之前调用下面方法,注意下面的方法只需要在程序集内调用一次

//使用CodePagesEncodingProvider去注册扩展编码。
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

这个代码是做注册,可以在启动的时候调用

获取 GBK 可以使用下面方法

//注册GBK编码
Encoding encodingGbk = Encoding.GetEncoding("GBK");

C# 判断文件编码

dotnet core 使用 GBK 编码

VisualStudio 编码规范工具 2.6 修改当前文件编码

win10 uwp 读取文本GBK错误

posted @ 2019-11-29 16:01  lindexi  阅读(117)  评论(0编辑  收藏  举报