ASP array Duplicate deletion function (Script House Enhanced Edition) _ Application Tips

Source: Internet
Author: User

Because to write a thing to use, so Baidu a bit, incredibly have a friend to write, and more than, have not seriously tested, only on the character can, but on the number can not, and very poor versatility, need to modify the real use. No way to write on their own, after testing completely no problem, and the idea is very convenient, the code is very short, as follows:

Copy 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
%>

Use methods and functions to represent:
1, two parameters in the Cxarraynull (CXSTR1,CXSTR2) function:
CXSTR1: The array variable to be instrumented can be null or otherwise unknown error data, or return "Nodate" for error data when it is empty.
CXSTR2: An array of split symbols that can be empty, or Chr (13), and so on, to automatically replace the output.
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 cloud-dwelling community enhanced version solves the last comma problem in the array.
Copy 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 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.