如何在不丢失前导零的情况下递增整数?
这是我的代码。
for i = week1From to week1To
dayWeek1(ctr)=i
ctr=ctr+1
next
如果我的变量是这样的话。
week1From = 03
week1To = 07
结果将
dayWeek1(1) = 3
dayWeek1(2) = 4
dayWeek1(3) = 5
dayweek1(4) = 6
dayWeek1(5) = 7
我怎么能这样做?
dayWeek1(1) = 03
dayWeek1(2) = 04
dayWeek1(3) = 05
dayweek1(4) = 06
dayWeek1(5) = 07
答案 0 :(得分:1)
在内部,没有前导0. 3是3而4是4.前导0仅在您查看值或在需要前导0的其他上下文中使用时才需要。所以只需在输出值时添加它,例如:
Response.Write "0" & dayWeek1(i) & vbCrLf
如果您的值为0-99并且您希望1位数值(0-9)具有前导0,那么这是一个小技巧:
Response.Write Right("0" & value, 2)
这将输出最右边的2位数字,因此1变为“01”,99变为“099”,但只打印最右边的2位数字,因此“99”。