Encoding.GetEncoding可以UWP应用程序无法正常工作

编程入门 行业动态 更新时间:2024-10-23 11:19:11
本文介绍了Encoding.GetEncoding可以UWP应用程序无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要编码一些文本文件的本地字符。

在我的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应用程序无法正常工作

本文发布于:2023-11-10 06:20:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574591.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   应用程序   工作   Encoding   GetEncoding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!