gpt4 book ai didi

c# - 编码 UTF-7 的 StreamWriter 问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:51:03 25 4
gpt4 key购买 nike

我有一个 UTF-7 格式的文本文件,我想创建另一个具有相同数据的文件,如下所示:

    using (var sw = new StreamWriter(@"D:\toto.csv.copy", false, Encoding.UTF7))
{
using (var sr = new StreamReader(@"D:\toto.csv", Encoding.UTF7))
{
string line;
while (null != (line = sr.ReadLine()))
{
sw.WriteLine(line);
}
}
}

在原始文件中,第一行是:¤TEST¤在复制文件中,第一行是:+AKQ-TEST+AKQ-

原始文件是UTF-7,当我在 Debug模式下观察行变量时,我可以在行变量中看到“¤TEST¤”。

你能帮帮我吗?

非常感谢

最佳答案

尝试在编写器上使用自定义编码以允许在输出中使用可选字符。

UTF7Encoding allowOptionals = new UTF7Encoding(true);

using (var sw = new StreamWriter(@"D:\toto.csv.copy", false, allowOptionals))
{
using (var sr = new StreamReader(@"D:\toto.csv", Encoding.UTF7))
{
string line;
while (null != (line = sr.ReadLine()))
{
sw.WriteLine(line);
}
}
}

关于c# - 编码 UTF-7 的 StreamWriter 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3984220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com