使用Visual Basic编辑文本文件 [英] Edit a Text File with Visual Basic

查看:85
本文介绍了使用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()

推荐答案

你必须

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


这篇关于使用Visual Basic编辑文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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