gpt4 book ai didi

c# - 如何格式化文本文件中的数据

转载 作者:行者123 更新时间:2023-11-30 22:44:29 24 4
gpt4 key购买 nike

我有一个字符串生成器,它包含电子邮件 ID(它包含数千个电子邮件 ID)

StringBuilder sb = new StringBuilder();
foreach (DataRow dr2 in dtResult.Rows)
{
strtxt = dr2[strMailID].ToString()+";";
sb.Append(strtxt);
}

string filepathEmail = Server.MapPath("Email");
using (StreamWriter outfile = new StreamWriter(filepathEmail + "\\" + "Email.txt"))
{
outfile.Write(sb.ToString());
}

现在数据像这样存储在文本文件中:

abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com; abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;abc@gmail.com;ab@gmail.com;

但我需要将它们存储为每行应该只有 10 个电子邮件 ID,这样我看起来不错**

知道如何在 .txt 文件中格式化数据吗?任何帮助都会很棒

最佳答案

只需在循环中添加一个计数器并每 10 行附加一个换行符。

int counter = 0;
StringBuilder sb = new StringBuilder();
foreach (DataRow dr2 in dtResult.Rows)
{
counter++;
strtxt = dr2[strMailID].ToString()+";";
sb.Append(strtxt);
if (counter % 10 == 0)
{
sb.Append(Environment.NewLine);
}
}

关于c# - 如何格式化文本文件中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3412491/

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