在文本列表中追加每一行

时间:2011-08-17 11:53:08

标签: vb.net append line text-files

我有一个文件名列表,其位置如下:

  

C:\ ICT \ AUTOCAD_2010 \的定制\ 20090409 \ 20090409.lsp   c:\ ICT \ AUTOCAD_2010 \ Customisations \ Advanced Offset \ LSP \ ADVANCED   OFFSET.lsp c:\ ICT \ AUTOCAD_2010 \ Customisations \ LockDWG \ LSP \ LockDWG.lsp   C:\ ICT \ AUTOCAD_2010 \ LSP \ acad2010doc.lsp

该列表非常基本,但应附加说:

  

(加载“c:\ ICT \ AUTOCAD_2010 \ Customisations \ 20090409 \ 20090409.lsp”)   (加载“c:\ ICT \ AUTOCAD_2010 \ Customisations \ Advanced Offset \ LSP \ ADVANCED OFFSET.lsp”)   (加载“c:\ ICT \ AUTOCAD_2010 \ Customisations \ LockDWG \ LSP \ LockDWG.lsp”)   (加载“c:\ ICT \ AUTOCAD_2010 \ LSP \ acad2010doc.lsp”)

如何用VB.net完成?

1 个答案:

答案 0 :(得分:0)

如果您的文件不是太大,那么您可以执行以下操作:

Dim fileContents As String, contentArray As String()
Dim updateContents As New StringBuilder("")

'read the file contents in
fileContents = My.Computer.FileSystem.ReadAllText("C:\TestInput.txt")
'split the contents on the space delimiter - this method will fail if you have a space in your filename
contentArray = fileContents.Split(" "c)
'loop through each file found in the data and format as required
For Each fileString As String In contentArray
    updateContents.Append(String.Format("(load {0}{1}{0}) ", Chr(34), fileString))
Next
'write out the newly formatted file
My.Computer.FileSystem.WriteAllText("C:\TestOuput.txt", updateContents.ToString, True)