Jump to content
Sign in to follow this  
erifash

New String Parser!

Recommended Posts

After searching on the forums and help file I have created a string parser that only uses two lines of code. I made it because I needed to parse some html for a web-spider i'm making that harvests links and such...

Okay:

$sz_str = string to parse

$sz_before = text that comes before the info you want

$sz_after = text that comes after the info you want

Func _Parse($sz_str, $sz_before, $sz_after)
  Local $sz_sp1 = StringSplit($sz_str, $sz_before, 1), $sz_sp2 = StringSplit($sz_sp1[$sz_sp1[0]], $sz_after, 1)
  Return $sz_sp2[1]
EndFunc

Any comments/questions are greatly appreciated! :(

Share this post


Link to post
Share on other sites

Eh, regexp is probably a bit faster. If this was introduced before, it would've been much more appriciated :(

Good idea, bad timing.


"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

Happens to the best of us :(


"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

Here's the example: (it actually works!)

$url = "http://www.google.com"
$file = "html.txt"
If not _INetActive() Then Exit
InetGet($url, $file)
$html = FileRead($file, FileGetSize($file))
FileDelete($file)
MsgBox(0, "_Parse() - " & $url, _Parse($html, "Google - Searching ", " web pages"))

Func _Parse($sz_str, $sz_before, $sz_after)
  Local $sz_sp1 = StringSplit($sz_str, $sz_before, 1), $sz_sp2 = StringSplit($sz_sp1[$sz_sp1[0]], $sz_after, 1)
  Return $sz_sp2[1]
EndFunc

Func _INetActive()
  If @IPAddress1 <> "127.0.0.1" Then Return 1
  Return 0
EndFunc

Share this post


Link to post
Share on other sites

I just made a script THIS morning... It count's the number of links on a webpage. But I want to write one in C++ now :(


FootbaG

Share this post


Link to post
Share on other sites

It's in the beta, look in the help file for 'StringRegExp'


"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...