字符串截断问题

samillboy 2004-04-06 06:48:31
hidden_single=TS6, TS5, TS4, TS8, TS7, TS2, TS1, TS9, TS3, Group14, Group3, Group2
DelID=TS5, TS8, TS1, Group3, Group2

这样两个字符串我要的结果是:TS6,TS4,TS7,TS2,TS9,TS3,Group14
然后存到数据库中
...全文
24 点赞 收藏 10
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dullwolf 2004-04-06
<SCRIPT LANGUAGE=vbs >
'功能:从字符串A中排除字符串B中有的,取差集
A="TS6, TS5, TS4, TS8, TS7, TS2, TS1, TS9, TS3, Group14, Group3, Group2"
B="TS4, TS7, TS1, TS3, Group14, Group3, Group2"
C=""
for each aaa in split(A,",")
tag =false '找到的标记
for each bbb in split(B,",")
if trim(aaa)=trim(bbb) then
tag=true '找到就退出循环
exit for
end if
next
if not tag then C= ", " &aaa & C
next
msgbox mid(C,3)
</SCRIPT>
回复
dullwolf 2004-04-06
<SCRIPT LANGUAGE=vbs >
s="hidden_single=TS6, TS5, TS4, TS8, TS7, TS2, TS1, TS9, TS3, Group14, Group3, Group2 DelID=TS5, TS8, TS1, Group3, Group2"
s=replace(s,", ",",")
s=replace(s,"hidden_single=","")
s=replace(s,"DelID=","")

for each aaa in split(s)
msgbox aaa
next
</SCRIPT>
回复
loveweb 2004-04-06
temp=split(DelID,",")
hidden_single=","&hidden_single
for i=0 to len(DelID)-1
a=","&temp(i)
Replace(hidden_single,"a","")
next
Response.write right(hidden_single,len(hidden_single)-1)
=========
hidden_single和DelID 是变的没关系啊一样可以替换啊
回复
A = split(hidden_single,",")
B = split(DelID,",")

for i = 0 to ubound(A)
for j =0 to ubound(B)
if A(i) = B(j) then
break;
end if
t = t & "," & A(i)
next
next

我没试过,不一定能运行起,主要是方法:
将两个数组元素进行比较,如果没有相同的便用变量t纪录
回复
samillboy 2004-04-06
还没有找到更好的办法
回复
dullwolf 2004-04-06
<SCRIPT LANGUAGE=vbs >
s="hidden_single=TS6, TS5, TS4, TS8, TS7, TS2, TS1, TS9, TS3, Group14, Group3, Group2 DelID=TS5, TS8, TS1, Group3, Group2"
s=replace(s,", ",",")
A=split(s,"=")
for each aaa in A
for each bbb in split(aaa)
if instr(bbb,",")>0 then msgbox bbb
next
next
</SCRIPT>
回复
QQgenie 2004-04-06
TO 楼主:一定要这么传吗?有没更好更简单的
回复
samillboy 2004-04-06
hidden_single和DelID 的值是变的从前一个页面过来的所以我觉得应该用两个数组来解决,但我解决不了,请各位高手帮忙解决
回复
loveweb 2004-04-06
temp=split(DelID,",")
hidden_single=","&hidden_single
for i=0 to len(DelID)-1
a=","&temp(i)
Replace(hidden_single,"a","")
next
Response.write right(hidden_single,len(hidden_single)-1)
回复
孟子E章 2004-04-06
笨方法
<script language=vbscript>
hidden_single="TS6, TS5, TS4, TS8, TS7, TS2, TS1, TS9, TS3, Group14, Group3, Group2"
DelID="TS5, TS8, TS1, Group3, Group2"
b=Split(DelID,",")
hidden_single=replace(hidden_single," ","")
for i = lbound(b) to ubound(b)
hidden_single=replace(hidden_single,Trim(b(i)),"")
next
hidden_single=replace(hidden_single,",,",",")
hidden_single=Left(hidden_single,Len(hidden_single)-1)
msgbox hidden_single
</script>
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告