codice:
Function SplitStringEvery(strIn,n)
Dim index,ar()
index=-1
while len(strIn)>n
index=index+1
redim preserve ar(index)
ar(index) = Mid(strIn,1,n)
strIn=Mid(strIn,n+1)
Wend
if Len(StrIn)>0 then
redim preserve ar(index+1)
ar(index+1)=StrIn
End if
SplitStringEvery=ar
End Function
Dim Ar,Elm
Ar = SplitStringEvery("CIAOTEST1234",4)
for each elm in ar
Response.Write "-" & Elm & "
"
next
Oppure, con l'eleganza delle regExp:
codice:
Function SplitStringEvery(strIn,n)
Dim Re,Matches,ar(),i,e
Set Re = New RegExp
Re.Global = True
Re.Pattern = "([\w\W]{1," & n & "})"
Set Matches = Re.Execute(StrIn)
e = Matches.Count-1
Redim ar(e)
For i=0 to e
ar(i) = Matches.Item(i).Value
Next
SplitStringEvery = ar
Set Re = Nothing
End Function