ASP Filter Array repeated data functions (enhanced edition) _ javascript skills

Source: Internet
Author: User
The implementation code of asp does not repeat the array data, which is finer and stronger than the previous version. You can choose as needed. Function Code:

The Code is as follows:


<% '************************************* ******************
'Filtering array repeated function name: array_no (cxstr1, cxstr2, cxstr3)
'Cxstr1: any string, automatically recognized
'Cxstr2: delimiter in cxstr1.
'Cxstr3: string at a certain position in the extraction result. If it is equal to 0, all is returned. If it is greater than the array marker, the end is returned.
'Used in 2D arrays
'*************************************** ****************
Function array_no (cxstr1, cxstr2, cxstr3)
If len (cxstr3)> 0 then
If not IsNumeric (cxstr3) then
Array_no = "sorry, parameter 3 must be a number"
Exit Function
End if
Else
Array_no = "sorry, parameter 3 must be a number"
Exit Function
End if
If isarray (cxstr1) then
Array_no = "sorry, parameter 1 cannot be an array"
Exit Function
End if
If cxstr1 = "" or isempty (cxstr1) then
Array_no = "no data"
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
Array_no = right (sss, len (sss)-len (cxstr2 ))
Array_no = left (array_no, len (array_no)-len (cxstr2 ))
If cxstr3 <> 0 then
Cx_sp = split (array_no, cxstr2)
If cxstr3> ubound (cx_sp) then
Array_no = cx_sp (ubound (cx_sp ))
Else
Array_no = cx_sp (cxstr3)
End if
End if
End function %>



The following is the test code:

The Code is as follows:


<% S1 = "abc, aa, bb, cdef, bc, abcdef, hhgg, gggg, cde, edc"
S2 = "33,333, 14"
S3 = ""
S4 = "sdf, abc, 12, 2, abc"
S5 = split (s4)
Response. write "when the string is a character:" & array_no (s1, ",", 0 )&"
"
Response. write "when the string is a number:" & array_no (s2, ",", 0 )&"
"
Response. write "when the string is null:" & array_no (s3, ",", 0 )&"
"
Response. write "when the string is mixed:" & array_no (s4, ",", 0 )&"
"
Response. write "when the string is an array:" & array_no (s5, ",", 0 )&"
"
Response. write "when the string is an unknown variable:" & array_no (s33, ",", 0 )&"
"
Response. write "when a certain digit is extracted, it does not exceed the lower mark:" & array_no (s1, ",", 2 )&"
"
Response. write "when a certain digit is extracted, when the cursor is exceeded:" & array_no (s1, ",", 200 )&"
"%>


Test results:

The Code is as follows:


String: abc, aa, bb, cdef, bc, abcdef, hhgg, gggg, cde, edc
When the string is a number: 14,333
When the string is null: No data
When the strings are mixed: sdf, abc
When the string is an array: Sorry, parameter 1 cannot be an array
When the string is an unknown variable: No data
When a certain digit is extracted, when the cursor is not exceeded: bb
When a certain digit is extracted, when the cursor is exceeded: edc



Enhanced version:Fixed common array errors

The Code is as follows:


<%
'*************************************** ****************
'Filtering array repeated function name: array_no (cxstr1, cxstr2, cxstr3)
'Cxstr1: any string, automatically recognized
'Cxstr2: delimiter in cxstr1.
'Cxstr3: string at a certain position in the extraction result. If it is equal to 0, all is returned. If it is greater than the array marker, the end is returned.
'Used in 2D arrays
'*************************************** ****************
Function array_no (cxstr1, cxstr2, cxstr3)
If len (cxstr3)> 0 then
If not IsNumeric (cxstr3) then
Array_no = "sorry, parameter 3 must be a number"
Exit Function
End if
Else
Array_no = "sorry, parameter 3 must be a number"
Exit Function
End if
If isarray (cxstr1) then
Array_no = "sorry, parameter 1 cannot be an array"
Exit Function
End if
If cxstr1 = "" or isempty (cxstr1) then
Array_no = "no data"
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
Array_no = right (sss, len (sss)-len (cxstr2 ))
Array_no = left (array_no, len (array_no)-len (cxstr2 ))
If cxstr3 <> 0 then
Cx_sp = split (array_no, cxstr2)
If cxstr3> ubound (cx_sp) then
Array_no = cx_sp (ubound (cx_sp ))
Else
Array_no = cx_sp (cxstr3)
End if
End if
End function

S1 = "abc, aa, bb, cdef, bc, abcdef, hhgg, gggg, cde, edc, 333, 333,7 ,,,,"
S2 = "33,333, 14,333 ,,,,"
S3 = ""
S4 = "sdf, abc, 333, 2, abc ,,,,"
S5 = split (s4)
Response. write "when the string is a character:" & array_no (s1, ",", 0 )&"
"
Response. write "when the string is a number:" & array_no (s2, ",", 0 )&"
"
Response. write "when the string is null:" & array_no (s3, ",", 0 )&"
"
Response. write "when the string is mixed:" & array_no (s4, ",", 0 )&"
"
Response. write "when the string is an array:" & array_no (s5, ",", 0 )&"
"
Response. write "when the string is an unknown variable:" & array_no (s33, ",", 0 )&"
"
Response. write "when a certain digit is extracted, it does not exceed the lower mark:" & array_no (s1, ",", 2 )&"
"
Response. write "when a certain digit is extracted, when the cursor is exceeded:" & array_no (s1, ",", 200 )&"
"
%>


It mainly adds judgment

The Code is as follows:


Do while instr (cxstr1, ",")> 0
Cxstr1 = replace (cxstr1 ,",,",",")
Loop
If right (cxstr1, 1) = "," then
Cxstr1 = left (cxstr1, len (cxstr1)-1)
End if

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.