我的輸入是兩個字符串。我需要遍歷這兩個字符串之間的每個值(包括值本身)。迭代兩個字符串之間的每個值
例如從AA
到CZ
(例如AA AB AC .. AY AZ BA BB .. CY CZ
)
合法值應該是可能的從0 - 9和AZ
迭代從01
到AD
應導致01 02 .. 09 0A .. 0Z .. 10 11 12 .. 9Z AA AB AC AD
字符串長度應可變但開始和結束始終具有相同的長度
AAA to ZZZ
有效
目前我完全卡住了。有什麼建議麼?
這是我目前的做法(我有限的字符串lengt 6和左填充值「0」,例如AAA
成爲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
這個工程相當不錯000001
到009999
但棘手的問題是,如果我有000A01
到000A20
。在第一次運行start6 equals 1
和stop6 equals 0
的用於循環退出。
@TimSchmelter我想避免因爲我當前的代碼是可怕的,但確定。 –
你的意思是start6等於1,** stop6 **等於0,對吧? – Han
@ Handoko.chen fixed,thx –