在文件中搜索特定字符串

时间:2018-09-17 12:37:11

标签: vb.net

我正在编写一个程序,该程序将能够搜索多个文件并在其中编辑特定的字符串,然后将其保存回原来的位置。

目前,我可以使用它来搜索文件并在富文本框中显示它。

告诉我文件中有多少行 并编辑文件中与特定文本相对的特定行,您有什么可以帮助我吗?

Public Class Form1

Dim Int1 As Integer

Dim Reader As StreamReader
Dim Lines As String = Int1
Dim Path As String = "C:\Users\callum.hirst\Desktop\DNS\burnsrecruitment.co.uk.dns"
Dim Content As String



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Int1 = New Integer
    Reader = File.OpenText(Path)
    Dim someString As String = "@                       3600    NS  nameserver2.i7net.co.uk." 'this Textbox for searching text example : Yellow
    Dim lines() As String = File.ReadAllLines(Path)
    Dim found As Integer = -1
    Dim i As Integer
    For i = 0 To lines.Length - 1 Step i + 1
        If lines(i).Contains(someString) Then
            found = i
            Int1 = i
            MsgBox(Int1)

            Exit For
        End If
    Next
    Reader = File.OpenText(Path)
End Sub

End Class

0 个答案:

没有答案