.NET Framework中可以这么获取:
var encoding = Encoding.GetEncoding("gb2312");
但在.NET Core中却出现下面的异常:
'gb2312' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
参考你提供的博文搞定!
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var encoding = Encoding.GetEncoding("GB2312");
需要安装 nuget 包 System.Text.Encoding.CodePages