在文本文件中写一个数组 [英] write an Array in textfile

查看:90
本文介绍了在文本文件中写一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,THE CODE PROJECT成员:
在文本文件中编写文字时有一个问题,我有一个字符串
14个数字,它们之间的间隔改变传送时间,但是每次删除前一行并写一个新的文本时,直到我只在文本文件中找到最后一行时才使用该探针:(请帮助我)
代码:

Hi dear THE CODE PROJECT members :
I have a probelm when writting in a text file i have a string
of 14 numbers and they change evey time with a space between them but the probelm every time it erase the previous line and write a new one until i find only the last line in the text file :( plz help me)
the code :

string path = @"D:\newS_R.txt";
     
                    TextWriter tw = new StreamWriter(path);
                    tw.WriteLine(textBox46.Text + " " + textBox45.Text + " " + textBox44.Text + " " + textBox43.Text + " " + textBox42.Text + " " + textBox41.Text + " " + textBox40.Text + " " + textBox39.Text + " " + textBox38.Text + " " + textBox37.Text + " " + textBox33.Text + " " + textBox34.Text + " " + textBox35.Text + " " + textBox36.Text + "" + Environment.NewLine);
                    tw.Close();

推荐答案

尝试一下
Environment.NewLine


http://msdn.microsoft.com/zh-CN /library/system.environment.newline(v=vs.71).aspx [ http://www.dotnetperls.com/newline [


http://msdn.microsoft.com/en-us/library/system.environment.newline(v=vs.71).aspx[^]
http://www.dotnetperls.com/newline[^]


您每次都创建一个新文件,尝试使用 ^ ],然后每次都附加您的数据.您还应该考虑在代码中使用更有意义的字段名称,因为上述示例中的字段名称将使您在将来维护代码时遇到噩梦.
You create a new file every time, try using this form[^] and append your data each time round. You should also consider using more meaningful field names in your code as the ones in your sample above will give you nightmares in the future maintenance of your code.


此代码一定会对您有所帮助. ..

This code will surely help you....

string path = @"D:\newS_R.txt";
using(StreamWriter sw = new StreamWriter(path,true))
{
     sw.WriteLine(textBox46.Text + " " + textBox45.Text + " " + textBox44.Text + " " + textBox43.Text + " " + textBox42.Text + " " + textBox41.Text + " " + textBox40.Text + " " + textBox39.Text + " " + textBox38.Text + " " + textBox37.Text + " " + textBox33.Text + " " + textBox34.Text + " " + textBox35.Text + " " + textBox36.Text + "" + Environment.NewLine);
}


这篇关于在文本文件中写一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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