使用Visual Basic编辑文本文件

问题描述:

亲爱的所有人,



我有以下代码来修改文本文件。我可以找到包含特定单词的所有行。但不知道如何编辑它。



Dear All,

I have below code to modify a text file. I can find all lines that contains a specific word. but not sure how to edit that.

Dim file As System.IO.File
        Dim reader As System.IO.StreamReader
        Dim line As String

        reader = file.OpenText("C:\Users\Shafiul Alam\Desktop\Test.txt")

        While reader.Peek <> -1

            line = reader.ReadLine()

            If line.Contains("DocCopies*") Then
                ' <RunList Run="Asset1" DocCopies="116" EndOfDocument="true">
                ' Get the Value of DocCopies
                ' Add +2 with 116
                ' Save the file
            Else
            End If

        End While

        reader.Close()

你必须

  • 阅读文件
  • 修改内存内容。
  • 将修改后的内存内容写回原始文件(覆盖它)。