asp下去除数组中重复项的方法

复制代码 代码如下:
<%
Function MoveR(Rstr)
Dim i,SpStr
SpStr = Split(Rstr,",")
For i = 0 To Ubound(Spstr)
If I = 0 then
MoveR = MoveR & SpStr(i) & ","
Else
If instr(MoveR,SpStr(i))=0 and i=Ubound(Spstr) Then
MoveR = MoveR & SpStr(i)
Elseif instr(MoveR,SpStr(i))=0 Then
MoveR = MoveR & SpStr(i) & ","
End If
End If
Next
End Function
response.write MoveR("abc,abc,dge,gcg,dge,gcg,die,dir,die")%>

结果是:abc,dge,gcg,die,dir

如果是两个数组进行对比,去掉相同的数组元素:

复制代码 代码如下:
<%
        Function mover(farray,sarray)
        a = Split(farray, ",")
            Set dic = CreateObject("Scripting.Dictionary")
            For k=0 To UBound(a)
             If a(k)<> "" Then dic.Add "_" & a(k), a(k)
            Next
            a = Split(sarray, ",")
            For k=0 To UBound(a)
                If a(k)<> "" Then
                    If dic.Exists("_" & a(k)) Then
                    dic.Remove "_" & a(k)
                    End If
                End If
            Next
            items = dic.Items()
            Set dic = Nothing
            moveR=Join(items, ",")
        End Function
n1 = "a,b,1,11,12,13,14,15,16,17,19,20,22"
n2 = "a,1,12,14,18,19,20"
response.write mover(n1,n2)
%>

结果是:

3.数组A中有为空的元素(如a=array("ww","ss","","dd","","ee")),
 想把这些空元素从数组A中去掉.并把去掉空元素有的数组赋给数组B.

复制代码 代码如下:
 str=""
for i = lbound(A) to ubound(A)
if A(i)<>"" then
if i<>lbound(A) then str = str + "," end if
str = str & A(i)
end if
next
b = split(str,",")

时间: 2024-11-05 10:55:03

asp下去除数组中重复项的方法的相关文章

asp下去除数组中重复项的方法_应用技巧

复制代码 代码如下: <%Function MoveR(Rstr) Dim i,SpStr SpStr = Split(Rstr,",") For i = 0 To Ubound(Spstr) If I = 0 then MoveR = MoveR & SpStr(i) & "," Else If instr(MoveR,SpStr(i))=0 and i=Ubound(Spstr) Then MoveR = MoveR & SpStr

JS简单去除数组中重复项的方法_javascript技巧

本文实例讲述了JS简单去除数组中重复项的方法.分享给大家供大家参考,具体如下: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> var arr = ["aaa","bb

运用javascript如何去除数组中重复的数字或者字符串?

问题描述 运用javascript如何去除数组中重复的数字或者字符串? 运用javascript如何去除数组中重复的数字或者字符串?谢谢了.方法越多越好,谢谢. 解决方案 JavaScript实现数组去除重复整理 javascript 去除数组中重复项的几种方法 解决方案二: 本人只会用JAVA写

去除数组中重复的项

数组|重复 <% '======================================'作者:阿里西西'时间:2005.12.20'作用:去除数组中重复的项'======================================Function MoveR(Rstr) Dim i,SpStr SpStr = Split(Rstr,",") For i = 0 To Ubound(Spstr)  If I = 0 then   MoveR = MoveR &

javascript 删除数组中重复项(uniq)_javascript技巧

可以直接使用的代码:修正版 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 下面是进阶教程与说明,喜欢跟深入的朋友可以参考下.首先让我们看下 YUI 是如何处理的: 复制代码 代码如下: var toObject = function(a) { var o = {}; for (var i = 0; i < a.length; i = i+1) { o[a[i]] = true; } return o; }; var keys = function(o) { var a=[], i;

c语言-关于去除数组中重复元素的问题

问题描述 关于去除数组中重复元素的问题 源代码:#include #include int main() { int *a; int n,i,j; scanf("%d",n); a=(int *)malloc(n*sizeof(int)); for (i=0;i<n;i++) scanf("%d",&a[i]); for (i=0;i<n;i++) for (j=1;j<n;j++) if (a[i]==a[j]) printf (&quo

PHP去除数组中重复的元素并按键名排序函数_php技巧

1.此函数的作用:去除数组中重复的元素并按键名排序 function assoc_unique($arr, $key) { $tmp_arr = array(); foreach($arr as $k => $v) { if(in_array($v[$key], $tmp_arr)) { unset($arr[$k]); } else { $tmp_arr[] = $v[$key]; } } sort($arr); return $arr; } 使用例子: $aa = array( array(

C# 去除数组中重复的元素简单代码

例子  代码如下 复制代码 string[] stringArray = { "aaa", "bbb", "aaa", "ccc", "bbb", "ddd", "ccc", "aaa", "bbb", "ddd" }; //List用于存储从数组里取出来的不相同的元素 List>string>

JavaScript去除数组里重复值的方法_javascript技巧

本文实例讲述了JavaScript去除数组里重复值的方法.分享给大家供大家参考.具体如下: var unique = function(origArr) { var newArr = [], origLen = origArr.length, found, x, y; for ( x = 0; x < origLen; x++ ) { found = undefined; for ( y = 0; y < newArr.length; y++ ) { if ( origArr[x] === n