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

删除数组指定字段
str=随机,随机,随机,随机,随机


str=1,3,2,1,2,3
如果我只想删除第2个逗号后面的那个2怎么能实现呢?

变成str=1,1,3,3,2

每一组都用“,”隔开,当然字段不是固定不变的 

------解决方案--------------------
str="1,3,2,1,2,3"
ar = split(str,"2")
str2 = ""
for i=0 to ubound(ar)
   str2 = str2 & ar(i)
   if i<>0 and i<>ubound(ar) then
       str2 = str2 & "2"
   end if
next
str2 = replace(str2, ",,",",")

------解决方案--------------------
引用:
str="1,3,2,1,2,3"
ar = split(str,"2")
str2 = ""
for i=0 to ubound(ar)
   str2 = str2 & ar(i)
   if i<>0 and i<>ubound(ar) then
       str2 = str2 & "2"
   end if
next
str2 = replace(str2, ",,",",")
为什么用2去分割?随机数中可能2都没有,而且只是指定要删除的位置不是每次都说删除2而且是第2个逗号后的。
<%
Function fun(arr,n)
Dim s_arr,i,list
s_arr=Split(arr,",")
For i=0 To UBound(s_arr)
If i<>n Then
list=list&","&s_arr(i)
End If
Next
fun=Mid(list,2)
End Function

Response.write fun("1,3,2,1,2,3",2) '删除逗号后第2个的字符 返回1,3,1,2,3
Response.write fun("1,3",2) '删除逗号后第2个的字符 返回1,3
%>