gpt4 book ai didi

C# StreamWriter 日文输出

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

出于某些奇怪的原因,我正在从 .txt(记事本)文件中读取数据,并且我只想去掉前 5 位数字。程序运行后,我的输出文件以我认为是日文的形式打印。我将在下面发布一些代码以及示例输入和输出。在追踪发生这种情况的原因时,我们将不胜感激。谢谢。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace BasicFileStripper
{
class Program
{
static void Main(string[] args)
{
//var encoding = new ASCIIEncoding();
StreamWriter write = new StreamWriter(@"C:\Users\Josh\Desktop\MillerEpicOutputs\ClientIds.txt");
StreamReader read = new StreamReader(@"C:\Users\Josh\Desktop\MillerEpicOutputs\j.txt");//, encoding);
string line;
int count = 0;
write.Write("{");
while ((line = read.ReadLine()) != null)
{
count++;
string copy = line.Substring(0, 5);
write.Write(copy + ",");
Console.WriteLine(line);
}
write.WriteLine("};");
write.WriteLine("Count: " + count);
write.Close();
}
}
}

示例输入:

68669 - (DO NOT USE)
68363 - 100 Men of Blue Hills
68364 - 10484 Marty LLC
68365 - 21st Century Therapy
69006 - 21st Century Therapy PC
69007 - 31 Dodge Partnership
69008 - 34 Merriam, LLC
69009 - 3525 Sage Council of Co-Owners

示例输出:㙻㘸㤶㘬㌸㌶㘬㐶㘬㶸㔶㘬㘬㘰㘬㜰㘬㠰㘬㤰㘬〱㜬㄰㐹㜬

最佳答案

我假设您正在尝试在记事本中读取输出(参见(this Wikipedia article)。将StreamWriter(String, Boolean, Encoding) constructorEncoding.UTF8一起使用,这将导致将 BOM 写入输出文件,让记事本读取它正确。如果您不需要在记事本中阅读它,请保持原样,并注意任何其他读取它并期望它是 UTF-8 的东西都可以正确读取它。

关于C# StreamWriter 日文输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25044320/

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