|
-
May 19th, 2002, 06:58 PM
#1
Thread Starter
Fanatic Member
Please help - string manipulation (easy)
http://www.site.com/index.html
https://www.site.com
www.site.com/
ftp://www.site.com
how can you msgbox the www.site.com and add a slash at the end if a slash doesnt exist (if its just a domain), and msgbox the whole string (without the http://) if its not just a domain? so for each one, it would msgbox www.site.com/, excpet for the first one, where it would msgbox www.site.com/index.html
more examples:
anyone know?
-
May 19th, 2002, 07:11 PM
#2
-= B u g S l a y e r =-
maybe something like this
VB Code:
Private Sub Command1_Click()
MsgBox ParsedAddress("http://www.site.com/index.html")
MsgBox ParsedAddress("https://www.site.com")
MsgBox ParsedAddress("www.site.com/")
MsgBox ParsedAddress("ftp://www.site.com")
End Sub
Private Function ParsedAddress(sWebAddr As String) As String
Dim iPos As Integer
iPos = InStr(sWebAddr, "://")
If iPos <> 0 Then
sWebAddr = Mid(sWebAddr, iPos + 3, Len(sWebAddr))
End If
iPos = InStr(sWebAddr, ".htm")
If iPos = 0 Then
If Right(sWebAddr, 1) <> "/" Then sWebAddr = sWebAddr & "/"
End If
ParsedAddress = sWebAddr
End Function
-
May 19th, 2002, 07:22 PM
#3
PowerPoster
This assumes you have VB6, a textbox with the multiline property set to true, and a command button named command1. It doesn't take into account that there is .html at the end because there are so many extensions, it would take a lot of coding to check every type of extension.
VB Code:
Private Sub Command1_Click()
yeah = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(yeah) - 1
j = InStr(1, yeah(i), "//")
If j > 0 Then
yeah(i) = Mid(yeah(i), j + 2)
End If
If Right(yeah(i), 1) <> "/" Then
yeah(i) = yeah(i) & "/"
End If
MsgBox yeah(i)
Next
End Sub
-
May 19th, 2002, 07:56 PM
#4
Thread Starter
Fanatic Member
peet - almost.. it still adds a / to the end of sites that are not simply domains (like http://www.site.com/p.php?me=*** returns www.site.com/p.php?me=***/)
any idea how to fix it?
midgets i couldnt get urs too work
-
May 19th, 2002, 08:10 PM
#5
-= B u g S l a y e r =-
yes, and as MidgetsBro pointed out, there will be loads of other stuff u have to take into consideration as u go along.. 
add "=" to the list :
VB Code:
Private Sub Command1_Click()
MsgBox ParsedAddress("http://www.site.com/index.html")
MsgBox ParsedAddress("https://www.site.com")
MsgBox ParsedAddress("www.site.com/")
MsgBox ParsedAddress("ftp://www.site.com")
MsgBox ParsedAddress("http://www.site.com/p.php?me=***")
End Sub
Private Function ParsedAddress(sWebAddr As String) As String
Dim iPos As Integer
iPos = InStr(sWebAddr, "://")
If iPos <> 0 Then
sWebAddr = Mid(sWebAddr, iPos + 3, Len(sWebAddr))
End If
If InStr(sWebAddr, ".htm") = 0 And InStr(sWebAddr, "?") = 0 Then
If Right(sWebAddr, 1) <> "/" Then sWebAddr = sWebAddr & "/"
End If
ParsedAddress = sWebAddr
End Function
-
May 19th, 2002, 08:17 PM
#6
Thread Starter
Fanatic Member
argh this is so frsutrating.. why is it so hard to get winsock to get a webpage? so much parsing that has to be done just to get the right string to be retrieved..
is there a function or anything that will change a webpage string into something that can be used with winsock to retrieve?
-
May 19th, 2002, 09:54 PM
#7
Thread Starter
Fanatic Member
-
May 19th, 2002, 10:13 PM
#8
The picture isn't missing
winsock does accept http:// and doesnt matter if it ends with / or not.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
May 19th, 2002, 10:25 PM
#9
PowerPoster
Hi
Assuming that u still want to parse the strings....
VB Code:
Private Sub Command1_Click()
Debug.Print NewString("www.site.com")
Debug.Print NewString("https://www.site.com/index.html")
Debug.Print NewString("http://www.site.com/s.php?g=5")
Debug.Print NewString("http://www.site.com/sub/sub.html")
End Sub
Private Function NewString(PassString As String) As String
Dim Posn As Integer
NewString = PassString
Posn = InStr(1, NewString, "//") 'Find first occurrence of //
If Posn > 0 Then 'If it is found
'You could add more checking for length of string here
NewString = Mid$(NewString, Posn + 2) 'trim off http etc
Else
Posn = 1 'Not found
End If
Posn = InStr(1, NewString, "/") 'Find first occurrence of /
If Posn = 0 Then NewString = NewString & "/" 'If not found, add it
End Function
-
May 20th, 2002, 01:08 AM
#10
Thread Starter
Fanatic Member
thanks beachbum! youre a genius
-
May 20th, 2002, 01:13 AM
#11
Consider urself lucky, n00b... it's very rare that BB gets out of his drag attire to present himself to the General forum, let alone help.
You should be honored.
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
|