[Gambas-user] An utility component for Gambas

Benoît Minisini gambas at ...1...
Mon Dec 1 15:41:46 CET 2014


Le 01/12/2014 15:33, Julio Sanchez a écrit :
> Hi, Benoît:
>
>   I think this function is interesting: Between
>
> Function Between(string_large as string, word_begin as string, word_end as
> string) as string
>
> DIM iinf AS Integer
> DIM isup AS Integer
> iinf = InStr(string_large,word_begin) + Len(word_begin)
> isup = InStr(string_large ,  word_end, iinf)
> RETURN Mid(string_large , iinf, isup - iinf)
>
> END
>
> The Between function is the one responsible for finding and extracting a
> part of a chain , this contained in a larger string between two words (or
> strings).
> example :
>
> string_large=" Hello Gambas [improvements] 3.6.9 [/improvements] :)"
> word1="[improvements]"
> word2="[/improvements]"
>
> text = Between(string_large,word1,word2)
>
> print text
> " 3.6.9"
>
>
> Note:
> Ideally extend to extract parts of web pages ( "<div>" and "</div>" , and
> supports nested structures "<div>")
>
> text = "<div> Hello <div> bye </div> <div> "
>
> content = between ( text , "<div>", "</div>")
>
> print content
> "<div> bye </div>"
>
> Regards
>
> Julio
>

Maybe I'm wrong, but you can already do that:

Try content = Scan(text, "*<div>*</div>*")[1]
If Error Then
   ' <div> not found
Else
   ' Got it
Endif

-- 
Benoît Minisini




More information about the User mailing list