如何在Windows应用商店/WinRT中使用ASCII编码将字符串保存到文本文件? [英] How to save string to text file with ASCII encoding in Windows store apps/WinRT?

查看:67
本文介绍了如何在Windows应用商店/WinRT中使用ASCII编码将字符串保存到文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力在Win8应用程序项目中使用 ASCII 编码将一些字符串保存到文本文件中.下面是一些代码片段:

I am trying hard to save some string to a text file with ASCII encoding in a win8 app project. Below is some of the code snippet:

StorageFile myfile = await ApplicationData.Current.LocalFolder.CreateFileAsync("test.txt");
await FileIO.WriteTextAsync(myfile, "abcd→1234");

但是它以 UTF-8 编码结束.

我已经在网上进行了大量搜索,但没有发现任何内容.所以我的问题是如何使用 ASCII 作为编码将字符串写入文本文件.谢谢!

I've done lots of search online and found nothing.So my question is how to write string to text file with ASCII as the encoding. Thanks!

推荐答案

据我所知,Windows应用商店应用程序不能使用非Unicode编码.但是,如果您的字符串仅包含代码点在U + 00到U + 7F(0..127)之间的字符,则UTF8和ASCII是相同的,因为UTF8被设计为与ASCII兼容.

As far as I know, Windows Store apps cannot use non-Unicode encodings. But if your string only contains characters with codepoints between U+00 and U+7F (0..127) then UTF8 and ASCII are identical, because UTF8 was designed to be ASCII-compatible.

因此,只需将其编码为UTF8并解码为ASCII.

So, just encode it as UTF8 and decode as ASCII.

这篇关于如何在Windows应用商店/WinRT中使用ASCII编码将字符串保存到文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆