ctrl + f (how to search in text...)

Steff_DK

Registered User.
Local time
Today, 12:17
Joined
Feb 12, 2005
Messages
110
Hi all,
I have a text message in a fixed format where each piece of info is enclosed in slashes like:

TYPE/TIME1/TIME2/ROLE//
F15/260730/260810/CAS//

How do I search the text string to find for instance the first "//" then search for "/" and then copy the "260730" part???

What is the ctrl +f in VB code???

Thanks!! :)

Steff
 
The Instr() function is what you want. That function gives me a headache everytime I need to use it so I will sign off on this thread with the advice that you need to search the forum for successful examples on how to use the Instr() function.
 
InStr(0,myString, "//") will return the 1-based position of the first slash in "//" - this number is what you want to return as the start of the next InStr function. So...

InStr(InStr(0,myString,"//"),myString,"/") will return the first instance of "/" after "//"

Or, your best bet is to just search the string manually...

Code:
'  myString is string you want to search
Dim i as Integer, myStr as String
fndSlash = False
For i = (InStr(0,myString,"//")+2) to len(myString)
   if fndSlash = True then
      if Mid$(myString,i,1) = "/" Then 
          Exit For
      else
          myStr=myStr & Mid$(myString,i,1)
      end if
   end if
   if Mid$(myString,2) = "/" then
      fndSlash = True
   end if
next i

I think this will return your number in myStr

HTH
 
Last edited:

Users who are viewing this thread

Back
Top Bottom