注册 登录
编程论坛 ASP技术论坛

又来救命了,求去重函数!!(已解决)

sass2008 发布于 2008-05-28 09:36, 925 次点击
现有两个字符串,要求找到相重的字符并去掉重复的.我下面的代码只能找到相重的只能去掉一个,哪里有错了!?!?!

<%   
f1="01 06 11 16 21 26 31"
t="31 32 33 11 01"
  a= kill(f1,t)

response.write a

'去重函数
Function kill(strurl,strurl2)
Dim   charstr   
  charstr=strurl & " " & strurl2
    charstr=trim(charstr)

  Dim   newstr   
  newstr=Split(charstr," ")   
   
  max=UBound(newstr)   
   
  Dim   i,j,flag   
   
  For   i=0   To   max-1   
  flag=newstr(i)   
  For   j=i+1   To   max-1   
  If   newstr(j)=flag   And   flag<>""   Then   
  newstr(j)=""   
  End   If   
  Next   
  If   newstr(i)<>""   Then   
     strurlxx=strurlxx & " " & newstr(i)&" "

  End   If   
  Next   
kill=strurlxx
End Function

  %>

=========解决代码!!感觉脑子真的是越来越不会拐弯了!!======
<%
t="01 06 11 16 21 26 31"
M1="31 32 33 11 01"
 a=split(t," ")
 a2=split(M1," ")
 a3=""
 for j=0 to ubound(a)
    mark=false
    for j2=0 to ubound(a2)
      if a(j)=a2(j2) then
        mark=true
      end if
     next
if mark=false then
         a3=a3 & " " & a(j)
      end if
  next
  response.write a3
%>

[[it] 本帖最后由 sass2008 于 2008-5-28 14:02 编辑 [/it]]

[[it] 本帖最后由 sass2008 于 2008-5-28 14:10 编辑 [/it]]
2 回复
#2
sass20082008-05-28 12:36
或者说求两个数组,判断去重函数也行

比如
数组1为"01 02 05 08 35 17 25 15 30 14 18 33"
数组2为"01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35"
要求编一个函数,把数组2中和数组1相重的数组部分去掉!!!!
#3
sass20082008-05-28 13:52
<%
a=split("01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35"," ")
a2=split("01 02 05 08 35 17 25 15 30 14 18 33"," ")
Dim NewArr()
ReDim Preserve NewArr(0)
'NewArr(0) = oldArr(0)
oldarr=a
matcharray=a2
for i = 0 to UBound(oldArr)
MatchArray = Filter(NewArr, oldArr(i), True,1)
iRepeatFlag = 1
For j = 0 To UBound(MatchArray)
iRepeatFlag = StrComp(oldArr(i), MatchArray(j), 1)
'一旦发现重复,立刻退出循环
If iRepeatFlag = 0 Then
Exit For
End If
Next
If IsNull(iRepeatFlag) Then iRepeatFlag = 2
If iRepeatFlag <> 0 Then
ReDim Preserve NewArr(UBound(NewArr) + 1)
NewArr(UBound(NewArr)) = oldArr(i)
End If
next
'显示除去重复内容后的结果
for each a in NewArr
response.write a&"<br>"
next


%>


好不容易找到了filter函数,但第二个参数又不支持变量!!!太郁闷了!!!
1