如何在新行中的文本文件中追加数据? [英] how to append data in text file in new line ?

查看:56
本文介绍了如何在新行中的文本文件中追加数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个表单,以使用四个文本框输入数据
并单击按钮,希望使用''|''运算符连接所有四个数据.
类似于 1 | abcd | gfd | 989898 ,并希望将此字符串保存到新行的文本文件中

例如,
文本文件数据....(data.txt)

i want make a form to input data using four textbox
and by clicking on button want to concate all four data using ''|'' operator.
like 1|abcd|gfd|989898 and want to save this string in to text file in new line

for example,
text file data....(data.txt)

1|abcd|ahm|989898
2|efgh|vad|545465
3|jhfd|jhf|356242



现在,如果我想插入第四个记录,例如 4 | dfdf | gfd | 545421
在新行中...

请给我一个适当的解决方案....



now if i want to insert 4th record like 4|dfdf|gfd|545421
in a new line...

please give me a proper solution....

推荐答案

一种方法是创建一个stringbuilder并使用它来创建字符串.然后使用 AppendAllText [
One way is to create a stringbuilder and use it to create the string. Then use AppendAllText[^] to create the file. For example:
StringBuilder sb = new StringBuilder();

sb.AppendFormat("{0}|{1}|{2}|{3}", "text 1", "text 2", "text 3", "text 4").AppendLine();
try {
   System.IO.File.AppendAllText(@"C:\temp\test.csv", sb.ToString());
} catch (System.Exception ex) {
}


这篇关于如何在新行中的文本文件中追加数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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