执行直到变量为 empty/null
Do While until variable is empty/null
不确定这是否可行:
myString = 313233
counter = Len(myString)
Do while counter > 0
position = 1
take = 2
response.write (" counter:" & counter)
first_two = Mid(myString, position, take)
response.write (" Each loop:" & first_two)
position = position + 2
counter = counter - 2
Loop
有人可以告诉我哪里出错了吗?或者这可以通过不同的方法实现吗?
上面的代码是 运行 一次并返回:31 而不是 31 32 33
谢谢。
更新:不久之后意识到我的错误,但现在位置不会增加以向上移动变量
您在 Do
循环开始时将 position
变量设置为 1
。每当调用 Mid()
时,都会传递 position = 1
,这将 return 31
.
通过将它移到循环之外来解决这个问题,这样 position
就可以递增。
myString = 313233
counter = Len(myString)
'Set before start of loop
position = 1
take = 2
Do while counter > 0
response.write (" counter:" & counter)
first_two = Mid(myString, position, take)
response.write (" Each loop:" & first_two)
'Use take variable so increment is always the same.
position = position + take
counter = counter - take
Loop
代码未经测试
不确定这是否可行:
myString = 313233
counter = Len(myString)
Do while counter > 0
position = 1
take = 2
response.write (" counter:" & counter)
first_two = Mid(myString, position, take)
response.write (" Each loop:" & first_two)
position = position + 2
counter = counter - 2
Loop
有人可以告诉我哪里出错了吗?或者这可以通过不同的方法实现吗?
上面的代码是 运行 一次并返回:31 而不是 31 32 33
谢谢。
更新:不久之后意识到我的错误,但现在位置不会增加以向上移动变量
您在 Do
循环开始时将 position
变量设置为 1
。每当调用 Mid()
时,都会传递 position = 1
,这将 return 31
.
通过将它移到循环之外来解决这个问题,这样 position
就可以递增。
myString = 313233
counter = Len(myString)
'Set before start of loop
position = 1
take = 2
Do while counter > 0
response.write (" counter:" & counter)
first_two = Mid(myString, position, take)
response.write (" Each loop:" & first_two)
'Use take variable so increment is always the same.
position = position + take
counter = counter - take
Loop
代码未经测试