求去掉重复字符串的函数。

longhorn008 2005-08-24 10:35:39
现有重复数据:1,1,1,2,2,3,4,5,6,6,6,7
现在求一个函数,就是将重复的数据过滤掉 ,类似于 sql 里的 distinct
...全文
195 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
大猫钓鱼 2005-08-24
  • 打赏
  • 举报
回复
这是最后的:
<%
Dim charstr
charstr="1,1,1,2,2,2,3,3,4,5,7,7,8,9"
Response.Write "原字符串:"&charstr
Response.Write "<br>"
Response.Write "现优化字符串:"&""

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
If newstr(i)=newstr(max-1) Then
Response.Write newstr(i)
Else
Response.Write newstr(i)&","
End If
End If

Next
%>
大猫钓鱼 2005-08-24
  • 打赏
  • 举报
回复
直接的过滤代码我好像没见过。

不过这样写就可以了。
<%
Dim charstr
charstr="1,1,1,2,2,2,3,3,4,5,7,7,8,9"

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
Response.Write newstr(i)&","
End If
Next
%>

同上,有中英输入法之分。
haver.G 2005-08-24
  • 打赏
  • 举报
回复
提醒一下我这里用的是半角的,如果用全角的你注意那","与","
haver.G 2005-08-24
  • 打赏
  • 举报
回复
<%
Dim str
Dim DistinctStr
Dim word
Dim i

str = "1,1,1,2,2,3,4,5,6,6,6,7"
DistinctStr = ""
for i = 1 to Len(str)
word = right(left(str,i),1)
if word<>"," then
if instr(DistinctStr,word)<=0 then
DistinctStr = DistinctStr&word&","
end if
end if
next
DistinctStr = Left(DistinctStr,Len(DistinctStr)-1)
Response.Write("原    串:"&str&"<br>去除重复:"&DistinctStr)
%>
大猫钓鱼 2005-08-24
  • 打赏
  • 举报
回复
按http://community.csdn.net/Expert/topic/3353/3353124.xml?temp=.4150659 里似乎VBS执行效率更高。不过不知道和IIS有没有关系。
大猫钓鱼 2005-08-24
  • 打赏
  • 举报
回复
to wzhiyuan(我是谁):那不是你的抛砖引玉嘛!呵呵。

问下:分别用VBS和JS写,哪个较好?
wzhiyuan 2005-08-24
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3832/3832202.xml?temp=.831402
你参考下这个,里面seeu1688(kangel)的算法,效率极高。

28,391

社区成员

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

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