我们试图仅将“a”的第一个实例替换为first second third
. 然后它应该循环并将“a”的第二个实例替换为新生成的值first second third
并继续这个循环,直到没有更多的“a”字符剩下并且每个“a”都是不同的值。但是输出的结果是不正确的。该代码正在擦除最后一个“a”之前的所有字符,然后替换最后一个“a”。
Dim message As String
Dim start As Integer = 1
Dim letterfinder As String
Dim timesLooped As Integer = 1
Dim length As Integer
Dim first As Integer
Dim second As Integer
Dim third As Integer
Dim count As Integer = 1
message = inputBox.Text
length = Len(message)
timesLooped = 0
While length > timesLooped
Dim random As New Random
letterfinder = Mid$(message, start, 1)
If letterfinder = "a" Then
first = random.Next(3, 9)
second = 1 \ first
third = 1 - second
outputBox.Text = Replace(message, letterfinder, first & second & third, [start], [count])
End If
timesLooped = timesLooped + 1
start = start + 1
End While