读书人

ASP的for 循环有关问题

发布时间: 2013-07-09 09:50:48 作者: rapoo

ASP的for 循环问题
if instr(ID,",")>0 then
dim idarr,i
idArr=split(ID) 'ID数组
for i = 0 to ubound(idArr)
'call DelNews(clng(idarr(i)))
sqltel="select * from student where ID=" & clng(idarr(i))
Set rstel= Server.CreateObject("ADODB.Recordset")
rstel.open sqltel,conn,1,3
phone = rstel("phione")'得到电话
phone = phone&","
response.write phone
next
else
'call DelNews(clng(ID)) 'ID
end if

我想得到 phone 的值为 15241549581,1241549584,xxxxxx,xxxxx
可以现在 总有一个,号结尾 15241549581,1241549584,xxxxxx,xxxxx,如何去掉
[解决办法]

if instr(ID,",")>0 then
dim idarr,i,phone
phone=""
idArr=split(ID) 'ID数组
for i = 0 to ubound(idArr)
'call DelNews(clng(idarr(i)))
sqltel="select * from student where ID=" & clng(idarr(i))
Set rstel= Server.CreateObject("ADODB.Recordset")
rstel.open sqltel,conn,1,3
if phone="" then
phone = rstel("phione")'得到电话
else
phone = phone&","&rstel("phione")
response.write phone
end if
next
else
'call DelNews(clng(ID)) 'ID
end if

[解决办法]
'笨办法一个
dim peo:peo=len(phone)
if peo>5 and right(phone,1)="," then
phone=left(phone,peo-1)
end if
response.write(phone)

[解决办法]
办法1:先把字符串处理一下再分割即可
办法2:循环次数减少1
办法3:循环中判断该值是否=""
[解决办法]
引用:
是啊 请问如何判断呢

for i = 0 to ubound(idArr)-1
[解决办法]
引用:
'笨办法一个
dim peo:peo=len(phone)
if peo>5 and right(phone,1)="," then


phone=left(phone,peo-1)
end if
response.write(phone)


赞同。我觉得这个反而省事。

读书人网 >ASP

热点推荐