Results 1 to 5 of 5

Thread: How would you loop a string

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    How would you loop a string

    hi all i have a string which im preforming certain case matches
    by instr function
    however my script only matches one item in the string so there for i need to loop it

    how would you loop a string ???? until there is no more of the string left to loop

    Cheers All
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    like this you mean?....
    VB Code:
    1. [color=blue]Dim[/color] strString [color=blue]As String[/color]() = "some stuff with spaces in to seperate!".Split(" ")
    2.         [color=blue]Dim[/color] strResult [color=blue]As String[/color]
    3.  
    4.         [color=blue]For Each[/color] strResult [color=blue]In[/color] strString
    5.             MessageBox.Show(strResult)
    6.         [color=blue]Next[/color]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Sorry should really show more code

    Start:

    do while "ant got a clue" basically until the string is all used up
    '------------------------------------------------------------------------
    'Start filtering for the links within the source code
    '------------------------------------------------------------------------
    StartPoint = 1

    StartPos = InStr(StartPoint, LineOfSite, "<a href=", vbTextCompare)

    If StartPos > 0 Then
    EndPos = InStr(StartPos, LineOfSite, Chr(62), vbTextCompare) 'Get the end part of the link

    If EndPos = 0 Then GoTo Restart_Loop
    LinkLength = EndPos - StartPos

    TheLink = Trim$(Mid$(LineOfSite, StartPos + 8, LinkLength - 8))

    If InStr(1, TheLink, " ") <> 0 Then
    TheLink = Trim$(Microsoft.VisualBasic.Left$(TheLink, InStr(1, TheLink, " ")))
    End If
    If Microsoft.VisualBasic.Left$(TheLink, 1) = Chr(34) Then
    TheLink = Mid$(TheLink, 2)
    End If
    If Microsoft.VisualBasic.Right$(TheLink, 1) = Chr(34) Then
    TheLink = Microsoft.VisualBasic.Left$(TheLink, Len(TheLink) - 1)
    End If

    'only get the urls that start with http
    'If Not Microsoft.VisualBasic.Left$(TheLink, 4) = "http" Then GoTo Restart_Loop
    'If Microsoft.VisualBasic.Left$(TheLink, 1) = "/" Then GoTo Restart_Loop
    'Skip allot of format
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".gif" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".jpg" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".png" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".mpg" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".avi" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 3) = ".rm" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 3) = ".ra" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".wav" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".mp3" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".asp" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".php" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 4) = ".jsp" Then GoTo Restart_Loop
    If Microsoft.VisualBasic.Right$(TheLink, 5) = ".aspx" Then GoTo Restart_Loop
    End If


    '------------------------------------------------------------------------
    'End Filtering the links
    '------------------------------------------------------------------------
    strLinks = strLinks & TheLink & vbCrLf

    Restart_Loop:
    Loop
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    To make your job easier you could use regular expression or you might want to use recursion

  5. #5

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    hey?

    IM trying to extract links from webpages so i guessed what i need to do is

    1 get the source code - done
    2 filter it for pages - kinda done Only finds one page hence why need the loop
    3 deal with the links

    this is why i was wondering how you loop via a string until the string has nothing left ?
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

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