使用VB.NET覆盖文本文件中的特定行 [英] Overwrite a specific line in a text file using VB.NET

查看:185
本文介绍了使用VB.NET覆盖文本文件中的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行以下操作:

更改文本文件中的行

[Path] = "c:\this\certain\path\"

与此行

[Path] = "c:\that\other\newer\path\"

这些路径的长度肯定会有所不同,因此我需要替换引号或完全删除该行并输入一个新的行,但要输入相同的位置,而不要附加到文档末尾.

These paths will most certainly be different lengths, so I need to either replace what's in the quotes or erase the line completely and enter a new one, but in the same spot, not appended to the end of the document.

推荐答案

这可以解决问题

    Dim thefile As String = "filepath"
    Dim lines() As String = System.IO.File.ReadAllLines("filepath")

    lines(number of line you want to replace) = "write what you want to replace here"

    System.IO.File.WriteAllLines(filepath, lines)

这篇关于使用VB.NET覆盖文本文件中的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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