首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

ASP的for 循环有关问题

2013-07-09 
ASP的for 循环问题if instr(ID,,)0 thendim idarr,iidArrsplit(ID)ID数组for i 0 to ubound(idArr)

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)


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

热点排行