|
-
Nov 12th, 2004, 09:00 PM
#1
Thread Starter
Sleep mode
Regex and URLs [Resolved]
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 ,
Last edited by Pirate; Nov 12th, 2004 at 09:42 PM.
-
Nov 12th, 2004, 09:19 PM
#2
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
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 12th, 2004, 09:20 PM
#3
Be sure to import System.Text.RegularExpressions
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 12th, 2004, 09:32 PM
#4
Thread Starter
Sleep mode
-
Nov 12th, 2004, 10:16 PM
#5
Frenzied Member
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.
-
Nov 12th, 2004, 10:50 PM
#6
Thread Starter
Sleep mode
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.
It won't work if a url starts with (https) . Nice try
-
Nov 13th, 2004, 10:14 AM
#7
Frenzied Member
That may be true, but allow me to quote myself
Of course that's assuming some things, but you know what I mean.
That 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.
Not that I recommend one over the other.
-
Nov 13th, 2004, 08:07 PM
#8
Thread Starter
Sleep mode
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 .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|