不确定这是否可行:
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
感谢。
更新:很快就实现了我的错误,但现在位置不会增加以提升变量
答案 0 :(得分:0)
您在position
循环开始时将1
变量设置为Do
。每当调用Mid()
时,它就会被传递position = 1
,它将返回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
代码未经测试