使用经典的asp分割字符串

时间:2017-05-02 12:57:22

标签: vbscript split asp-classic chunks

我有一个列表昏迷分隔值(a,b,c,d,e,f,g,h,....) 我希望将它们分成5个像(a,b,c,d,e)(f,g,h,i,j).... 有人可以帮我处理经典asp中的代码吗?

arr = Split(messto, ",") ' convert to array
totalemails = UBound(arr) ' total number of emails

if totalemails mod 5 = 0 then
    totalloops = int(totalemails/5) 
    else
    totalloops = int(totalemails/5) + 1
end if

x = 0 
y = 0
b = 0
for x = 0 to totalloops  


    for counter = (5* x)  to ((b+5)-1)
        if Trim(arr(counter)) <> "" and isnull(trim(arr(counter))) = false then 

        response.Write(Trim(arr(counter)))
        response.Write(counter & "<br>")
        mymssto =  mymssto & Trim(arr(counter)) & ","
        response.Write(mymssto)

        end if  

    next

1 个答案:

答案 0 :(得分:1)

您希望使用Mod()执行此操作,这是非常强大且未充分利用的功能。

这是一个基于问题代码的简单示例;

<%
Dim mumberToGroupBy: numberToGroupBy = 5
Dim index, counter, arr, messto

messto = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q"
arr = Split(messto, ",") ' convert to array

For counter = 0 To UBound(arr)
  'Can't divide by 0 so we need to make sure our counter is 1 based.
  index = counter + 1
  Call Response.Write(Trim(arr(counter)))
  'Do we have any remainder in the current grouping?
  If index Mod numberToGroupBy = 0 Then Response.Write("<br>")
Next
%>

输出:

abcde
fghij
klmno
pq

有用的链接