Extracting part of a string

Q

Question Boy

I need to extract part of a string.

I have a string that contain tons of garbage. I need to get the actual
content, but seem to be having difficulty.

The string a associated to my variable sFile, It starts off with garbage
then has my content then has garbage. The content always start with "Below
is the result of" and always end with "submit: TRANSMIT"

How can I extract the content. I've been trying using InStr, InStrRev and
Mid but can't seem to get it to work?

Thank you!!!

QB
 
P

Paolo

Hi QB,

Let's say your string is called str.

tmp_pos=instr(str,"Below is the result of"
str=mid(str,tmp_pos)
tmp_pos=instr(str,"submit: TRANSMIT"
str=left(str,tmp_pos+len("submit: TRANSMIT"))
Now str is stripped from garbage

This is aircode(untested) so test it

HTH Paolo
 
Q

Question Boy

That's what I thought too. I tried the InStr as you mention but it always
return 0 that the string is not found? and yet when I open the file in
Notepad it is there. Any other ideas?

QB
 
P

Paolo

As you say if it returns 0 it means that the string is not found.
Check that the search string is written exactly as in your string (e.g. no
double spaces or something like this).

In this statement I forgot the closing bracket
tmp_pos=instr(str,"Below is the result of"
It must be
tmp_pos=instr(str,"Below is the result of")

Regards
 
Q

Question Boy

There is no typo, I performed a copy/paste of the string. That why I am very
confused at this point.

QB
 

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

Top