Extracting part of a string

  • Thread starter Thread starter Question Boy
  • Start date Start date
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
 
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
 
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
 
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
 
There is no typo, I performed a copy/paste of the string. That why I am very
confused at this point.

QB
 
Back
Top