asp 输出ID数位不足8位 补0

来源:百度知道 编辑:UC知道 时间:2024/09/28 17:41:19
本ID是自动编号的,
rs("id")

我要显示id 不足8位前面补0,自动加的,当ID是一位数就补7个0 是2位数就补6个0 这样下去,

怎么搞的,

很遗憾asp没有直接能转换的函数,如下方法是最简单的。

right("00000000" & rs("id"),8)

format(rs("id"),"00000000")

ID=cstr(rs("ID"))
IF LEN(ID)<8 then
a=8-leN(ID)
end if
for i=1 to a
t=t&"0"
next
ID=t&"ID"
response.write ID

<%

if Len(Trim(rs("ID"))) >8 then
response.write "ID长度大于8!"
respinse.end
end if

if Len(Trim(rs("ID"))) =8 then
response.write Trim(rs("ID"))
else
Dim i,K,strTemp
K = 8-Len(Trim(rs("id")))
for i = 1 to K
strTemp = "0"&Trim(rs("id"))
next
response.write strTemp
end if
%>