parsing text from a log file

arcole

New member
Joined
Mar 15, 2008
Messages
4
Programming Experience
Beginner
ok i have been looking all over the web trying to figure out how to do this and i have found many things that are like what i want to do but just not it. i know its really easy but just cant figure it out seeing as i am some what of a noob to VB.

i have a log file that is in a format like this

(3:03:30) [Say] Arcole: test
(3:03:30) [Say] Arcole: test
(3:03:30) [Say] Arcole: test

now what i want to do is pull the info after the : "test" out and the info before the : to the ] "Arcole" so i would get

Arcole
test

the info i am trying to pull out will change so it cant look for arcole and test or at a set number of char it would need to look after the : and from the : to ]

if anyone can give me an idea where to look or what this is called it would help. some of the things i have been looking up is parsing, search by string, reading text files and they all seem to pull up this type of stuff so cant figure out what this type of thing is called.
 
VB.NET:
Dim s As String = "(3:03:30) [Say] Arcole: test"
s = s.Substring(s.IndexOf("]"c) + 2) ' = Arcole: test
Dim splitindex As Integer = s.IndexOf(":"c)
Dim first As String = s.Remove(splitindex) ' = Arcole
Dim second As String = s.Substring(splitindex + 2) ' = test
 
thank you for your help.

ok so i see how this works now if i was to put
VB.NET:
Dim s As String = "logfile.txt"
this work not work right i would need to load line by line into the string?

the best thing that i can think of would be to load each line into the app and remove that line from the log so it will not read it again.
 
There is a IO.File.ReadAllLines method that return a String array of all the lines in the file.
 
ya i saw that and was playing around with it but i dont think that will work. my app will be working with the log file in real time and everything i found for reading the log file wants to pull the whole file in and then write to the file and seeing as the log file is always be used overwriting it would not be a good idea. what i need to do is read 1 line then remove that line and move to next line without losing any new data that might of been added to the log.
 
That might pose a problem. You can however keep a record of how many lines you've processed and next time skip to that line and read out.
 
If there is any chance of the earlier entries in the file being altered then it might be sensible to double check by recording the last time processed as well and then you can check that it matches up with the last line.
 
Back
Top