日期:2014-05-16  浏览次数:20769 次

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