0 Replies - 136 Views - Last Post: 10 November 2014 - 10:03 AM Rate Topic: -----

#1 wizrd3d  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 14

regular expressions and number orientated strings

Posted 10 November 2014 - 10:03 AM

Dim Combinations As New List(Of String)
For x1 As Integer = 1 To 70
  For x2 As Integer = x1 + 1 To 70
    For x3 As Integer = x2 + 1 To 70
      For x4 As Integer = x3 + 1 To 70
              
        Dim numbers() As String = {x1.ToString, x2.ToString, x3.ToString, x4.ToString }
        lstData.Items.Add(String.Join(",", numbers))
        Application.DoEvents()
        Dim Regex As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("\d+")

        Dim Add As Boolean = True
        ‘checking if there are the same numbers in string
        Regex.matches(str,numbers(x4) & numbers(x5 +1))
        If m.count > Then Add = False
                                
        ‘if the add is true add number sequences to the list
        If Add Then Combinations.Add(numbers(x1) & "," & numbers(x2) & "," & numbers(x3) & "," & numbers(x4)
        lstData.Items.Add(String.Join(",", numbers))                                
      Next
    Next
  Next
Next





I've been learning more about regular expressions and they as complicated as they're they are also easy to use but I came across a stumbling block when it came to the code above. Whn I fun the normal combination string of code I get results like 1,2,3,6
1,2,3,7
1,2,3,8
That is all displayed in a listbox so I have been trying to remove all sequences with consecutive numbers and leave only those with either the same numbers or different numbers.basically I want to illiminate all sequences with consecutive numbers e.g 1,2,3,6 from populating my listbox,I learned about using regex and it was all goin well till I had to execute the solution below I just seemed to get errors,as you can see I use the true and false statements so if these restrictions are found to be true that all sequences regardles of the position of the numbers in the squence e.g 1,2,3,6 or 1,2,6,3 they not appear on the list.I need guidence as to how I can possibly archieve this goal

This post has been edited by AdamSpeight2008: 10 November 2014 - 10:16 AM
Reason for edit:: Poster put code tags around each line of code like a dumpty


Is This A Good Question/Topic? 0
  • +

Page 1 of 1