数组比较的问题

www_31365_com 2009-11-10 06:22:15
a = "12,13"

b = "112,113,214,315,163,271,118,119"


需要列出"118,119"
排除b中包含a的数字,a中的数字不是固定格式,比如12,但21也符合
...全文
102 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
www_31365_com 2009-11-15
  • 打赏
  • 举报
回复
5楼的朋友针对n1和n2一模一样的时候非常有用,但是我的条件是:排除b中包含a的数字,a中的数字不是固定格式,比如12,但21也符合,a是固定2位,b固定3位
yonkerking 2009-11-15
  • 打赏
  • 举报
回复
<%
n1 = "12,13,14,15,16,17"
n2 = "12,14,18,19,20"

a = Split(n1, ",")
Set dic = CreateObject("Scripting.Dictionary")
For k=0 To UBound(a)
If a(k)<> "" Then dic.Add "_" & a(k), a(k)
Next
a = Split(n2, ",")
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
Response.Write "最后得到: " & Join(items, ",")
%>
gingerkang 2009-11-15
  • 打赏
  • 举报
回复
中间的两位不是人吗,你有看?
不明确的问题更不知道怎么解答了
www_31365_com 2009-11-15
  • 打赏
  • 举报
回复
没有人赐教吗?
ACMAIN_CHM 2009-11-15
  • 打赏
  • 举报
回复
这是个算法问题。

你需要对 a = "12,13" 中每个数字来进行判断。如果B中有数字包含了A中的所有数字,则删除。
Msxindl_Com 2009-11-15
  • 打赏
  • 举报
回复
将 k=2 改为 k=len(c1(cc)) 更好.
Msxindl_Com 2009-11-15
  • 打赏
  • 举报
回复
你试试.应该能满足你的要求:


<%
dim a,b
a="12,13"
b="112,113,214,315,163,271,118,119"
d1=split(b,",")
c1=split(a,",")
for x=0 to ubound(d1)
for cc=0 to ubound(c1)
k=0
for m=1 to len(c1(cc))
c11=mid(c1(cc),m,1)
if instr(d1(x),c11)>0 then k=k+1
if k=2 then b=replace(b,d1(x),"")
next
next
next
if right(b,1)="," then b=left(b,len(b)-1)
d2=split(b,",")
for y=0 to ubound(d2)
if d2(y)<>"" then
str1=str1&d2(y)
if y < ubound(d2) then str1=str1&","
end if
next
response.write str1
%>
www_31365_com 2009-11-15
  • 打赏
  • 举报
回复
Dim strID, strCode
a = "12,13"
b = "112,113,214,315,163,271,118,119"

Dim j, jj, strFlag, tmp
Dim strIDtmp : strIDtmp = Split(a, ",")
Dim strCodeTmp : strCodeTmp = Split(b, ",")
Dim strPub : strPub = ""

'需要列出"118,119",排除b中包含a的数字,a中的数字不是固定格式,比如12,但21也符合

For j = 0 To UBound(strCodeTmp)
strFlag = False
For jj = 0 To UBound(strIDtmp)
If strFlag Then Exit For
If InStr(strCodeTmp(j), CStr(Mid(strIDtmp(jj), 1, 1))) = 0 And InStr(strCodeTmp(j), CStr(Mid(strIDtmp(jj), 2, 1))) = 0 Then
tmp = strCodeTmp(j)
strFlag = True
End If
Next
If strFlag Then strPub = strPub & Tmp & ","
Next
Response.Write "最后得到: " & strPub & "<br>"

上述代码哪里有问题,请赐教,如果把InStr改为>结果返回是b中包含a的数字,我要的是b中不包含a的数字
phpc 2009-11-10
  • 打赏
  • 举报
回复
用到数组的一些函数,split,ubound吧。

dim arrA,arrB
arrA=split(a,",")
arrB=split(b,",")

遍历arrB,和arrA[0] arrA[1]一个个比较排除就可以了。



----------------------------------------------
无忧统计www.51stat.net---打造强大的网页流量统计系统
lzp4881 2009-11-10
  • 打赏
  • 举报
回复
a是固定两位吗?
阳因定三位吗?

比如12,但21也符合

你说的范围太大吧,
那么12345呢,是不是12345,54321,12354,12453,...
也要算呢?

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧