Results 1 to 11 of 11

Thread: Please help - string manipulation (easy)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628

    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?

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    maybe something like this

    VB Code:
    1. Private Sub Command1_Click()
    2.     MsgBox ParsedAddress("http://www.site.com/index.html")
    3.     MsgBox ParsedAddress("https://www.site.com")
    4.     MsgBox ParsedAddress("www.site.com/")
    5.     MsgBox ParsedAddress("ftp://www.site.com")
    6. End Sub
    7.  
    8. Private Function ParsedAddress(sWebAddr As String) As String
    9.     Dim iPos As Integer
    10.     iPos = InStr(sWebAddr, "://")
    11.     If iPos <> 0 Then
    12.         sWebAddr = Mid(sWebAddr, iPos + 3, Len(sWebAddr))
    13.     End If
    14.    
    15.     iPos = InStr(sWebAddr, ".htm")
    16.     If iPos = 0 Then
    17.         If Right(sWebAddr, 1) <> "/" Then sWebAddr = sWebAddr & "/"
    18.     End If
    19.     ParsedAddress = sWebAddr
    20. End Function
    -= a peet post =-

  3. #3
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    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:
    1. Private Sub Command1_Click()
    2. yeah = Split(Text1.Text, vbCrLf)
    3. For i = 0 To UBound(yeah) - 1
    4.     j = InStr(1, yeah(i), "//")
    5.     If j > 0 Then
    6.         yeah(i) = Mid(yeah(i), j + 2)
    7.     End If
    8.     If Right(yeah(i), 1) <> "/" Then
    9.         yeah(i) = yeah(i) & "/"
    10.     End If
    11.     MsgBox yeah(i)
    12. Next
    13. End Sub
    <removed by admin>

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628
    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

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    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:
    1. Private Sub Command1_Click()
    2.     MsgBox ParsedAddress("http://www.site.com/index.html")
    3.     MsgBox ParsedAddress("https://www.site.com")
    4.     MsgBox ParsedAddress("www.site.com/")
    5.     MsgBox ParsedAddress("ftp://www.site.com")
    6.     MsgBox ParsedAddress("http://www.site.com/p.php?me=***")
    7. End Sub
    8.  
    9. Private Function ParsedAddress(sWebAddr As String) As String
    10.     Dim iPos As Integer
    11.     iPos = InStr(sWebAddr, "://")
    12.     If iPos <> 0 Then
    13.         sWebAddr = Mid(sWebAddr, iPos + 3, Len(sWebAddr))
    14.     End If
    15.    
    16.     If InStr(sWebAddr, ".htm") = 0 And InStr(sWebAddr, "?") = 0 Then
    17.         If Right(sWebAddr, 1) <> "/" Then sWebAddr = sWebAddr & "/"
    18.     End If
    19.    
    20.     ParsedAddress = sWebAddr
    21. End Function
    -= a peet post =-

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628
    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?

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628
    _

  8. #8
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    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 .

  9. #9
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    Assuming that u still want to parse the strings....
    VB Code:
    1. Private Sub Command1_Click()
    2.     Debug.Print NewString("www.site.com")
    3.     Debug.Print NewString("https://www.site.com/index.html")
    4.     Debug.Print NewString("http://www.site.com/s.php?g=5")
    5.     Debug.Print NewString("http://www.site.com/sub/sub.html")
    6. End Sub
    7.  
    8. Private Function NewString(PassString As String) As String
    9.     Dim Posn As Integer
    10.     NewString = PassString
    11.     Posn = InStr(1, NewString, "//") 'Find first occurrence of //
    12.     If Posn > 0 Then 'If it is found
    13.         'You could add more checking for length of string here
    14.         NewString = Mid$(NewString, Posn + 2) 'trim off http etc
    15.     Else
    16.         Posn = 1 'Not found
    17.     End If
    18.     Posn = InStr(1, NewString, "/") 'Find first occurrence of /
    19.     If Posn = 0 Then NewString = NewString & "/" 'If not found, add it
    20. End Function
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628
    thanks beachbum! youre a genius

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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
  •  



Click Here to Expand Forum to Full Width