VicTT Posted September 25, 2005 Posted September 25, 2005 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
w0uter Posted September 25, 2005 Posted September 25, 2005 (edited) usefull for the people that dont understand regexp. 1 improvement, use local. Edited September 25, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
blitzkrg Posted September 26, 2005 Posted September 26, 2005 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
w0uter Posted September 26, 2005 Posted September 26, 2005 stringinstring matches the first ocurance. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
VicTT Posted September 26, 2005 Author Posted September 26, 2005 (edited) If you want "hello this is a test" you can use _StringBetween($s,"</i>"&@CRLF&"<i>,"</i>") Edited September 26, 2005 by VicTT Quote Together we might liveDivided we must fall
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now