Extracting data from different positions of a string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all, here's the problem I have:

I have a text file that I believe was dumped from an old-school COBOL
bucketed file.

In each record is a chunk of data that I want to use, which will always
start with the same four letters, then a space, then it's the next 10
characters that I want. The trouble is, this useful string could be buried
anywhere within the record. My data looks something like this:

garbagegarbagegarbageABCD ##########garbagegarbage
garbageABCD ##########garbagegarbagegarbagegarbage
garbagegarbagegarbagegarbageABCD ##########garbage

Is there a way of extracting just the 10 characters after the ABCD that
always marks where it starts?

Thanks!
 
The following code will extract the first occurance of the string. If you
need to extract all occurances (your example shows more that one) you would
have to create code to continue searching until all are found:
= Mid(strGarbage, Instr(strGarbage, "ABCD")+5,10)
 
Thank you, I'll give that a try!

Klatuu said:
The following code will extract the first occurance of the string. If you
need to extract all occurances (your example shows more that one) you would
have to create code to continue searching until all are found:
= Mid(strGarbage, Instr(strGarbage, "ABCD")+5,10)
 

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