Using Regex (or perhaps any other way), how can I strip the homepage of a URL like this one :
http://www.vbforums.com/newthread.ph...ead/forumid=25
so I get this result :
http://www.vbforums.com
Thanks ,
Printable View
Using Regex (or perhaps any other way), how can I strip the homepage of a URL like this one :
http://www.vbforums.com/newthread.ph...ead/forumid=25
so I get this result :
http://www.vbforums.com
Thanks ,
Found this and modified it a little...
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim s As String = "http://www.vbforums.com/newthread.php?s=&action/newthread/forumid=25" Dim sp As String = "^(http:\/\/)?([^\/]+)" Dim ms As MatchCollection ms = Regex.Matches(s, sp) MsgBox(ms(0).Value) End Sub
Be sure to import System.Text.RegularExpressions
:)
Works solid . Thanks !
Another way, not as cool as regex, but certainly less cryptic
VB Code:
Dim s As String = "http://www.vbforums.com/newthread.php?s=&action/newthread/forumid=25" Dim chop As Integer chop = s.IndexOf("/", 7) Dim s2 As String = s.Substring(0, chop) Debug.WriteLine(s2)
Of course that's assuming some things, but you know what I mean.
It won't work if a url starts with (https) . Nice try ;)Quote:
Originally posted by Mike Hildner
Another way, not as cool as regex, but certainly less cryptic
VB Code:
Dim s As String = "http://www.vbforums.com/newthread.php?s=&action/newthread/forumid=25" Dim chop As Integer chop = s.IndexOf("/", 7) Dim s2 As String = s.Substring(0, chop) Debug.WriteLine(s2)
Of course that's assuming some things, but you know what I mean.
That may be true, but allow me to quote myselfThat example hard coded the seventh position. One could easily determine the position of a double slash, if that worked for you. It's not my point to try do out do regex, but as your title implied, I'm just suggesting another way.Quote:
Of course that's assuming some things, but you know what I mean.
Not that I recommend one over the other.
Yah I guess , it's another way . It's cool and if I add some stuff it would as accurate as regex (lots of work) . Thanks though . This gives some insights to other things ;) .