【问题标题】:splitting a string in chunks using classic asp使用经典的 asp 将字符串分割成块
【发布时间】:2017-05-02 12:57:21
【问题描述】:

我得到了一个逗号分隔值列表 (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

【问题讨论】:

标签: vbscript split asp-classic chunks


【解决方案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

有用的链接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    相关资源
    最近更新 更多