Jump to content

_StringBetween()


VicTT
 Share

Recommended Posts

Func _StringBetween($s,$from,$to)
$x=StringInStr($s,$from)+StringLen($from)
$y=StringInStr(StringTrimLeft($s,$x),$to)
Return StringMid($s,$x,$y)
EndFunc

This is very useful when parsing webpages..Suppose you get the HTML code of a webpage(by _InetGetSource..but I'm a InetGet fan..) and want some magic value that's between two KNOWN strings..

For example:

...
<span class=red> This is the string you wanna get </span>

You'd just call _StringBetween($s,"<span class=red> ","</span>")

Comments are welcome, optimizations, bug-reports, suggestions..whatever you want..It helped my ass out when I was parsing such a webpage, and thought it might be useful to someone..Cheers..

Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

how does it know (or how do you specify) specific lines?

what i mean is

say there is html like this

<i> blah blah </i>

<i>hello this is a test </i>

<i> test test test</i>

your example is "You'd just call _StringBetween($s,"<span class=red> ","</span>")"

so i'd call _StringBetwen($s,"<i>","</i>")

how do i know which line it will get? or how do i specify?

say i just want the "hello this is a test" line?

thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...