簡體   English   中英

在文本文件中搜索單詞,然后從那里繼續閱讀vb.net

[英]Search for word in text file and continue reading from there vb.net

如標題所述,我想在文本文件中搜索特定的單詞,然后從此開始閱讀文本。

以下是一個代碼片段

Dim path As String = "c:\temp\test.txt"
        Dim readall As String
        Dim i As Integer


            If File.Exists(path) Then
                File.Delete(path)
            End If

            Dim sw As StreamWriter = New StreamWriter(path)
            sw.WriteLine("Hello")
            sw.WriteLine("i am here")
            sw.WriteLine("to test")
            sw.WriteLine("the class")
            sw.Close()

            Dim sr As StreamReader = New StreamReader(path)
            readall = sr.ReadToEnd
            sr.Close()

所以現在我已經讀取了文件並將其存儲為字符串readall。 我如何寫回文件,但現在從單詞“ to”開始,例如outpout文本文件為

測試課程

我希望我能說清楚

readall中搜索“ to”的第一個匹配項,並將其余的readall (以“ to”開頭)存儲到變量stringToWrite

Dim stringToWrite As String
stringToWrite = readall.Substring(IndexOf("to"))

然后將stringToWrite寫入文件:

Dim sw As StreamWriter = New StreamWriter(path)
sw.write(stringToWrite)
sw.Close()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM