Get servername from a given url?

BlitzMax Forums/BlitzMax Beginners Area/Get servername from a given url?

Grisu(Posted 2009) [#1]
Hello guys!

I'm looking for a fast function to extract the servername from a given url...

Example:
"http://www.blitzbasic.com/Community/_search.php?bbs=BlitzMax&forum=&terms=url&method=advanced&case=no&results=topic&user=&submit=Search"

Returns:
"www.blitzbasic.com"

Don't want to re-invent the wheel here.

Grisu


Brucey(Posted 2009) [#2]
wxURI ? :-p

Maybe there's some code in the archives?


Grisu(Posted 2009) [#3]
Haven't found such a code via a forum search.

wx? I don't need a whole module... :)

Where can I get that stuff?


Brucey(Posted 2009) [#4]
Fair enough :-)
(just that you said you didn't want to re-invent wheels)

I'm sure it's not that difficult to parse and get the info you need.


fredborg(Posted 2009) [#5]
Print getBaseURL("http://www.blitzbasic.com/Community/_search.php?bbs=BlitzMax&forum=&terms=url&method=advanced&case=no&results=topic&user=&submit=Search")
Print getBaseURL("www.blitzbasic.com/Community/_search.php?bbs=BlitzMax&forum=&terms=url&method=advanced&case=no&results=topic&user=&submit=Search")
Print getBaseURL("file://www.blitzbasic.com?bbs=BlitzMax&forum=&terms=url&method=advanced&case=no&results=topic&user=&submit=Search")

Function getBaseURL:String( url:String )

	Local noProtocol:String
	Local a:String[] = url.split("://")
	If a.length>1
		noProtocol = a[1]
	Else
		noProtocol = a[0]
	EndIf
	Return noProtocol.split("/")[0].split("?")[0]
	
EndFunction



Grisu(Posted 2009) [#6]
That's more compact than anything else I've come up with so far. :(

Thanks a lot Fredborg!