I am using the below code to find the character number for 'Cblah3', and then find the next space after 'Cblah3', then using substring to get the text in the middle. This works brilliantly - what i dont know is how to find at what character the end of the line is, so i could use either the next space or the end of the line which ever is nearer. The testfile is posted at the bottom of the post.
Thanks in advance for any help.
Private Sub BlahTestButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlahTestButton.Click
Dim reader As New System.IO.StreamReader("c:\blahtest.txt")
Dim textfromfile As String = reader.ReadToEnd() 'use the ReadToEnd() method to read the whole file
Dim ResultStart As Integer
Dim ResultEnd As Integer
Dim Results As String
ResultStart = (InStr(textfromfile, "Cblah3"))
MsgBox(ResultStart)
'Starts searching for a space after the first find was found,
'the +1 is needed to ensure it searches after the first find.
ResultEnd = InStr(ResultStart + 1, textfromfile, " ")
MsgBox(ResultEnd)
'Finds the text between the characters references, the (ResultEnd - ResultStart)
'is required to work out the difference and just take the text for that section
Results = textfromfile.Substring(ResultStart, (ResultEnd - ResultStart))
MsgBox(Results)
'Returns the length of the string, to compare to the actual length to see
'if theres a space in it or not
MsgBox(Results.Length)
End Sub
Ablah1 Ablah2 Ablah3
Bblah1 Bblah2 Bblah3
Cblah1 Cblah2 Cblah3
Dblah1 Dblah2 Dblah3
Eblah1 Eblah2 Eblah3
Fblah1 Fblah2 Fblah3
Gblah1 Gblah2 Gblah3
Hblah1 Hblah2 Hblah3
Thanks in advance for any help.
Private Sub BlahTestButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlahTestButton.Click
Dim reader As New System.IO.StreamReader("c:\blahtest.txt")
Dim textfromfile As String = reader.ReadToEnd() 'use the ReadToEnd() method to read the whole file
Dim ResultStart As Integer
Dim ResultEnd As Integer
Dim Results As String
ResultStart = (InStr(textfromfile, "Cblah3"))
MsgBox(ResultStart)
'Starts searching for a space after the first find was found,
'the +1 is needed to ensure it searches after the first find.
ResultEnd = InStr(ResultStart + 1, textfromfile, " ")
MsgBox(ResultEnd)
'Finds the text between the characters references, the (ResultEnd - ResultStart)
'is required to work out the difference and just take the text for that section
Results = textfromfile.Substring(ResultStart, (ResultEnd - ResultStart))
MsgBox(Results)
'Returns the length of the string, to compare to the actual length to see
'if theres a space in it or not
MsgBox(Results.Length)
End Sub
Ablah1 Ablah2 Ablah3
Bblah1 Bblah2 Bblah3
Cblah1 Cblah2 Cblah3
Dblah1 Dblah2 Dblah3
Eblah1 Eblah2 Eblah3
Fblah1 Fblah2 Fblah3
Gblah1 Gblah2 Gblah3
Hblah1 Hblah2 Hblah3