This article is a function to delete duplicate arrays under asp and has been tested.
Because I wanted to write something for use, I searched on Baidu and found that a friend had written it randomly, and there were quite a lot of it. I had not tested it carefully. It only worked with characters, but not with numbers. It also had poor versatility and needed to be modified. Can actually be used. I had no choice but to write it myself. After testing, there was no problem at all. The idea was very convenient and the code was very short, as follows:
Copy the code code as follows:
<%
function cxarraynull(cxstr1,cxstr2)
if isarray(cxstr1) then
cxarraynull = "Sorry, parameter 1 cannot be an array"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
cxarraynull = "nodate"
Exit Function
end if
ss = split(cxstr1,cxstr2)
cxs = cxstr2&ss(0)&cxstr2
sss = cxs
for m = 0 to ubound(ss)
cc = cxstr2&ss(m)&cxstr2
if instr(sss,cc)=0 then
sss = sss&ss(m)&cxstr2
end if
next
cxarraynull = right(sss,len(sss) - len(cxstr2))
cxarraynull = left(cxarraynull,len(cxarraynull) - len(cxstr2))
end Function
%>
Using methods and functions:
1. Two parameters in the cxarraynull(cxstr1,cxstr2) function:
cxstr1: The array variable to be detected can be empty or other unknown error data. When it is empty or error data, "nodate" is returned.
cxstr2: The splitting symbol of the array, which can be empty or chr(13), etc., and the output will be automatically replaced.
2. Test code:
<%
s="1,2,3,4,2,3,5,3"
s=cxarraynull(s,",")
response.write s
%>
Output: 1,2,3,4,5
The enhanced version of Script House solves the comma problem in the last digit of the array.
Copy the code code as follows:
<%
function cxarraynull(cxstr1,cxstr2)
if isarray(cxstr1) then
cxarraynull = "Sorry, parameter 1 cannot be an array"
Exit Function
end if
if cxstr1 = "" or isempty(cxstr1) then
cxarraynull = "nodate"
Exit Function
end if
do while instr(cxstr1,",,")>0
cxstr1=replace(cxstr1,",,",",")
loop
if right(cxstr1,1)="," then
cxstr1=left(cxstr1,len(cxstr1)-1)
end if
ss = split(cxstr1,cxstr2)
cxs = cxstr2&ss(0)&cxstr2
sss = cxs
for m = 0 to ubound(ss)
cc = cxstr2&ss(m)&cxstr2
if instr(sss,cc)=0 then
sss = sss&ss(m)&cxstr2
end if
next
cxarraynull = right(sss,len(sss) - len(cxstr2))
cxarraynull = left(cxarraynull,len(cxarraynull) - len(cxstr2))
end function
%>
Test code:
Copy the code code as follows:
s="1,2,3,4,55,55,55,333,333,2,3,5,3,88,,,,,,,66,,66,,,,,,,,,,,,, ,,,,,,,,,,,,"
s=cxarraynull(s,",")
response.write s