我需要编码一些文本文件的本地字符。
在我的Windows 8.1商店应用,我可以用 Encoding.GetEncoding() 方法通常为:
Encoding.GetEncoding(窗口-1254),但在UWP应用程序,我得到这个异常:
更多信息:Windows的1254'是不支持的编码名称。有关定义自定义编码的信息,请参阅Encoding.RegisterProvider方法的文档。
我不知道如何使它通过使用 Encoding.RegisterProvider 方式,任何想法?
解决方案我们需要使用CodePagesEncodingProvider注册包括在特定的供应商扩展编码。请参见 CodePagesEncodingProvider 类
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Encoding.GetEncoding(窗口-1254);
参考的msdn.microsoft/en-us/library/system.text.encodingprovider(v=vs.110).aspx
.NET框架类库提供了一个静态的财产,的病人:System.Text.CodePagesEncodingProvider.Instance ,返回一个 EncodingProvider对象这使得整套编码的桌面.NET Framework类库上可用提供给.NET核心的应用程序。
相关线程在MSDN论坛:的 Encoding.RegisterProvider - 如何使用
I need to encode some text files for native characters.
In my Windows 8.1 Store app, I could use Encoding.GetEncoding() method normally:
Encoding.GetEncoding("windows-1254")But in UWP app, I got this exception:
Additional information: 'windows-1254' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
I don't know how to make it work by using Encoding.RegisterProvider method, any ideas?
解决方案We need to use the CodePagesEncodingProvider to register extended encodings included in that specific provider. See CodePagesEncodingProvider Class
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Encoding.GetEncoding("windows-1254");Ref msdn.microsoft/en-us/library/system.text.encodingprovider(v=vs.110).aspx
The .NET Framework Class Library provides one static property, P:System.Text.CodePagesEncodingProvider.Instance, that returns an EncodingProvider object that makes the full set of encodings available on the desktop .NET Framework Class Library available to .NET Core applications.
The related thread in MSDN forum: Encoding.RegisterProvider -- How to use?
更多推荐
Encoding.GetEncoding可以UWP应用程序无法正常工作
发布评论