在文本文件中搜索word并继续从中读取vb.net
正如标题所说,我想在文本文件中搜索特定单词,然后从该点开始阅读文本 下面是一个代码片段在文本文件中搜索word并继续从中读取vb.net,vb.net,string,text,text-files,vb.net-2010,Vb.net,String,Text,Text Files,Vb.net 2010,正如标题所说,我想在文本文件中搜索特定单词,然后从该点开始阅读文本 下面是一个代码片段 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 s
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()
现在我已经读取了文件并将其存储到string readall中。
如何写回文件,但现在从“to”开始
例如,输出文本文件将是
检验
班级
我希望我清楚地告诉自己搜索
readall
第一次出现的“to”,并将readall
的其余部分存储到变量stringToWrite
:
Dim stringToWrite As String
stringToWrite = readall.Substring(IndexOf("to"))
然后将stringToWrite
写入文件:
Dim sw As StreamWriter = New StreamWriter(path)
sw.write(stringToWrite)
sw.Close()
在
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()