首页 > 解决方案 > 在文件中搜索特定字符串

问题描述

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

目前我拥有它,因此它可以搜索文件并将其显示在富文本框中。

告诉我文件中有多少行并编辑文件中与特定文本相反的特定行,你们中的任何人都可以帮助我吗?

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

标签: vb.net

解决方案


推荐阅读