Locate/parse text

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I want to locate a line in a text file and then return the remainder of the
line. The line I am looking for begins like this:

//*****

Does anyone have an example of how to do this? Thanks.

Mark
 
Mark said:
I want to locate a line in a text file and then return the remainder of the
line. The line I am looking for begins like this:

//*****

Does anyone have an example of how to do this?

Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

You can use the string's 'StartsWith' method to check if the line start with
a certain sequence of characters. Then you can use 'Mid' or the string's
'Substring' method to get the part of the string on the right side of the
prefix.
 
Here's a little snippet from an app of mine. LineInput(1) represents
each line of the logfile being looped through. Modify as necessary.

R/
T$


For Each machine In ListBox1.Items
Try
log = "\\" & machine & "\" & MyVal5 &
"\" & MyVal4
logdatetime = File.GetLastAccessTime(log)
FileOpen(1, log, OpenMode.Input)
Do Until EOF(1)
strText = LineInput(1)
If InStr(strText, "exit status [0]") > 0 Then :
ExitC = "Radconct Exit Status [0]" : success = "y" : End If
If InStr(strText, "exit status [857]") > 0 Then
: ExitC = "Radconct Exit Status [857]" : success = "y" : End If
If InStr(strText, "exit status [858]") > 0 Then
: ExitC = "Radconct Exit Status [858]" : success = "y" : End If
If InStr(strText, "exit status [811]") > 0 Then
: ExitC = "Radconct Exit Status [811]" : success = "y" : End If
If InStr(strText, "exit status [200]") > 0 Then
: ExitC = "Radconct Exit Status [200]" : success = "n" : End If
If InStr(strText, "exit status [202]") > 0 Then
: ExitC = "Radconct Exit Status [202]" : success = "n" : End If
If InStr(strText, "exit status [650]") > 0 Then
: ExitC = "Radconct Exit Status [650]" : success = "n" : End If
If InStr(strText, "exit status [709]") > 0 Then
: ExitC = "Radconct Exit Status [709]" : success = "n" : End If

Loop
FileClose(1)
If ExitC = "" Then : success = "Exit Code Not Found"
End If
Dim oItem1 As ListViewItem =
Results.Items.Add(UCase(machine))

oItem1.SubItems.Add(" " & ExitC & " ")
oItem1.SubItems.Add(" " & logdatetime & " ")

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top