Results 1 to 2 of 2

Thread: Affecting the next occurrance in a for loop.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2008
    Posts
    20

    Affecting the next occurrance in a for loop.

    Code:
    Dim t As String = source
    
            For Each m As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(t, ">.*?<")
    
                search = m.Value.Substring(1).Remove(m.Value.Length - 2)
    
                If search = "" Or haku = " " And counter < 337 Then
                    counter = counter + 1
                ElseIf search <> "" And search <> " " And counter > 337 Then
    
                    If column = 0 Then
                        '-------------
                        If search.Length = 6 Then
                            length6 = True
                        Else
                            length6 = False
                        End If
                        '-------------
                        If length6 = True Then
                            jump = True
                        Else
                            jump = False
                        End If
                        '--------------
                        If jump = False Then
    
                            TextBox2.Text = TextBox2.Text & search & "   "
                            counter = counter + 1
                            column += 1
                        End If
                        '--------------
                    Else
                        TextBox2.Text = TextBox2.Text & search & ControlChars.CrLf
                        counter = counter + 1
                        column -= 1
                    End If
    
                End If
            Next

    What you see here, is a code that picks everything written in between > and < markers from a source code on a website. What it returns is always a time stamp in between 00:00 and 23:59 and a string.

    Or almost always. There is a few instances where there are two times in a row and not every other, effectively breaking the system.

    Also, when this happens, the first time of the two has a "-" after it, i.e 18:00-

    What I've been trying to do, is making the program recognize when there is an extra character (the -), delete the extra character, and then jump over the next result in the search (the following time). This would completely resolve the problem.

    The thing is, no matter how much I go through it in my head, I can't seem to think of a way to affect the NEXT result without screwing up the current result or all the following results.

    As you can see, my code is faulty. What it does now is an emergency method (as my teacher review of the code is coming up real soon) it jumps over the time with the extra character, and lists the following time. This however is not ultimately wanted, because in the bigger scheme of things, it displays the incorrect time for the incorrect string.

    Search variable holds all the results of the regex search, for easier handling, and is used for checking for the extra character.

    Length6 variable is boolean for determining if the result had the "-" or not.

    The column variable is to list the time and the string on the same line in the textbox.

    Jump is the variable that makes the code skip the conditioned result from the search.

    The counter variable, that might seem extra, is just for extra conditioning, its use is to prevent the first 337 instances of the search.

    Thanks a bunch in advance for anyone willing to throw around some ideas. For the sake of saving precious time, please try to say it in code as I am a beginner and there are so much commands and the like I don't know how to use and what they do.

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Affecting the next occurrance in a for loop.

    Alter your regular expression so it only returns the data you want
    Code:
    Dim t = "<tag>09:30</tag><tag>09:30-10:30</tag>"
    For Each m As Match In Regex.Matches(t, "(?<=\>)\d\d:\d\d(?=\<)")
        Debug.WriteLine(m.Value)
    Next
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

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