简体   繁体   English

VB.NET将文本追加到现有CSV文件中的行尾

[英]VB.NET Append text to the end of a line in an exiting CSV file

How can I append text to the end a line in a text file with lines already there in VB.NET? 如何在VB.NET中已有行的文本文件的末尾附加文本?

For example my text file looks like this: 例如,我的文本文件如下所示:

header1,header2,header3 value1,value2,value3 stuff1,stuff2,stuff3 header1,header2,header3 value1,value2,value3 stuff1,stuff2,stuff3

and I want to add new text to the end of each line so it looks like this: header1,header2,header3,newheader value1,value2,value3,newvalue stuff1,stuff2,stuff3,newstuff 我想在每行的末尾添加新文本,使其看起来像这样:header1,header2,header3,newheader value1,value2,value3,newvalue stuff1,stuff2,stuff3,newstuff

I know that in Perl you can point to the line and then act on it, is there some VB.net way to do this? 我知道在Perl中您可以指向该行,然后对其执行操作,是否有一些VB.net方法可以做到这一点?

If the file isn't too big, the simplest is, probably, to use the IO.File.ReadAllLines method to read the file into memory and modify the data and write it back with the WriteAllLines method. 如果文件不是太大,则最简单的方法可能是使用IO.File.ReadAllLines方法将文件读入内存并修改数据,然后使用WriteAllLines方法将其写回。

For very large files you're probably looking at reading each line modifying it and writing it to a different file. 对于非常大的文件,您可能正在看读取修改它的每一行并将其写入不同的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM