split text file

jkatshor

Member
Joined
Mar 20, 2009
Messages
11
Programming Experience
Beginner
Hello,
I have read the contents of a text file that looks like the following lines into vb;

this_date = "1-2-09"
// user input
//user input
this_date = "2-22-2009"
//user input
this_date = "4-7-2009"
// user input
//user input
// user input
//user input

(there is no limit to how many "this_date" lines or "//user input lines" there are in the file and additions are made often )

When I read the file in vb I wish to only capture the last "this_date" only as the rest are irrelevant.

Any suggestions,
Thank you in advance....
 
Last edited:
Dim MyLastDate As String = Mid(MyTextFileString, InStrRev(MyTextFileString, "this_date = "), InStr(InStrRev(MyTextFileString, "this_date = "), MyTextFileString, vbCrLf, CompareMethod.Text))

Where MyTextFileString is your text file loaded into a string. This "should" search backward through the string looking for the last "this_date = ". Once it finds it it takes all text from that point in the string to the next carriage return (you may have to change the VbCrLf to jsut a VbCr or VbLf). Thisnk that's what you want.

-Allan
 
Back
Top