My input are two string. I need to loop over every value (including values itself) between these two strings.
For example from AA
to CZ
(e.g. AA AB AC .. AY AZ BA BB .. CY CZ
)
Legal values should be possible from 0 - 9 AND A-Z
Iteration from 01
to AD
should result in 01 02 .. 09 0A .. 0Z .. 10 11 12 .. 9Z AA AB AC AD
String length should be variable but start and end have always the same length
AAA to ZZZ
valid
Currently I am totally stuck. Any suggestions?
This is my current approach (I limited the string lengt to 6 and left fill the values with "0", e.g. AAA
becomes 000AAA
value1 = "A01"
value2 = "A20"
value1 = value1.PadLeft(6, "0")
value2 = value2.PadLeft(6, "0")
Dim start1 As Integer = Asc(value1.Substring(0, 1))
Dim start2 As Integer = Asc(value1.Substring(1, 1))
Dim start3 As Integer = Asc(value1.Substring(2, 1))
Dim start4 As Integer = Asc(value1.Substring(3, 1))
Dim start5 As Integer = Asc(value1.Substring(4, 1))
Dim start6 As Integer = Asc(value1.Substring(5, 1))
Dim stop1 As Integer = Asc(value2.Substring(0, 1))
Dim stop2 As Integer = Asc(value2.Substring(1, 1))
Dim stop3 As Integer = Asc(value2.Substring(2, 1))
Dim stop4 As Integer = Asc(value2.Substring(3, 1))
Dim stop5 As Integer = Asc(value2.Substring(4, 1))
Dim stop6 As Integer = Asc(value2.Substring(5, 1))
For p1 As Integer = start1 To stop1
For p2 As Integer = start2 To stop2
For p3 As Integer = start3 To stop3
For p4 As Integer = start4 To stop4
For p5 As Integer = start5 To stop5
For p6 As Integer = start6 To stop6
Dim result as string = Convert.ToChar(p1) &Convert.ToChar(p2) & Convert.ToChar(p3) & Convert.ToChar(p4) & Convert.ToChar(p5) & Convert.ToChar(p6)
Console.WriteLine(result)
Next
Next
Next
Next
Next
Next
This works pretty well for 000001
to 009999
but the tricky part is if I have 000A01
to 000A20
. On the first run start6 equals 1
and stop6 equals 0
the for for loop exits.