Solved

Parsing a String

Posted on 2004-03-20
6
368 Views
Last Modified: 2010-05-01
What is the best way to parse out a substring within the following string?

Daily Operations Status ReportDaily Operations Status ReportCritical Application Cycle End TimesInsurance/ISAInsurance DataBase(Critical Path - BT30004) ended at: 2:00Insurance DataBase(LASTISA) ended at: 3:00

I wrote the following parse function to pull out the time, but it returns: ) ended at: 2:00

Private Function FilterBT4(BT4Str)
  Dim i As Integer, b As Integer
  Dim FinalStr As String
  i = InStr(1, BT4Str, "4) ended at: ")
  If i Then
   i = i + 1
   b = InStr(i, BT4Str, "Insurance")
    If b Then
     FinalStr = Mid(BT4Str, i, b - i)
     FilterBT4 = FinalStr
    End If
 End If
End Function

I just want it to pull out:   2:00

Any ideas??
Thanks
Rich
0
Comment
Question by:rkckjk
  • 2
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 10642095
Dim pStart as Integer, pEnd as Integer
Dim pTime as String

pStart = InStr(1, Text1.Text, "ended at:") + 10
pEnd = InStr(pStart, Text1.Text, "Insurance")
pTime = Trim(Mid(Text1.Text, pStart, pEnd - pStart))

that is assuming the text u want to parse out of is Text1, u can change that
0
 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 10642099
pTime would then be ur time.. u can test it by putting:
MsgBox pTime
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10642150
'Assuming BT4Str = "Daily Operations Status ReportDaily Operations Status ReportCritical Application Cycle End TimesInsurance/ISAInsurance DataBase(Critical Path - BT30004) ended at: 2:00Insurance DataBase(LASTISA) ended at: 3:00"

Then this is your function:

Private Function FilterBT4(BT4Str)
FilterBT4 = Right(BT4Str, Len(BT4Str) - InStrRev(BT4Str, "ended at:", -1) - 9)
End Function

S
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10642328
Shauli, your code will find the "ended at: 3:00" which is at the VERY END of the string, and not the ended at: 2:00 which the original questioner was searching for.

rkckjk, your original code:

Private Function FilterBT4(BT4Str)
  Dim i As Integer, b As Integer
  Dim FinalStr As String
  i = InStr(1, BT4Str, "4) ended at: ")
  If i Then
   i = i + 1
   b = InStr(i, BT4Str, "Insurance")
    If b Then
     FinalStr = Mid(BT4Str, i, b - i)
     FilterBT4 = FinalStr
    End If
 End If
End Function


was VERY close, you simply needed to add 11 to i, rather than 1:

Private Function FilterBT4(BT4Str)
  Dim i As Integer, b As Integer
  Dim FinalStr As String
  i = InStr(1, BT4Str, "4) ended at: ")
  If i Then
   i = i + 11
   b = InStr(i, BT4Str, "Insurance")
    If b Then
     FinalStr = Mid(BT4Str, i, b - i)
     FilterBT4 = FinalStr
    End If
 End If
End Function


The extra 10 is the number of characters in 'ended at: ', since the value of i (in the line -- i = InStr(1, BT4Str, "4) ended at: ")) is the location of the first 'e' in 'ended;, and you want the location of the 2 that foloows thast location...hence you must add the numbers of characters to offset to the right, to get the value you want.

AW
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10642359
Arthur_Wood, You are absolutely right, I misread the question :(
S
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 50 total points
ID: 10642376
hey, it happens to the best of us.  Just wanted to make sure that rkckjk did not get confused.

AW
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 81
DIR issue 7 50
VB6 - Convert HH:MM into Decimal 8 51
How to make an ADE file by code? 11 79
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now