Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Parsing a String

Posted on 2004-03-20
6
Medium Priority
?
374 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:Richard Kreidl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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