如何去掉字符串制定的字符

yyh112 2009-11-03 06:10:54
n=1,2,3,4,5,6,12,11,34,23,

制定字符

i=1,11,3,4

最后得到:n=2,5,6,12,34,23,


如果 i=13,
则 报错 字符串N中不包含13
...全文
39 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lzp4881 2009-11-03
  • 打赏
  • 举报
回复
<%
str1="1,2,3,4,5,6,12,11,34,23"
str2="1,11,3,4"
response.write formatStr(str1,str2)
%>
<%
function formatStr(str1,str2)
arr=split(str2,",")
str1=","&str1&","
m=false
for each item in arr
if instr(str1,","&item&",")>0 then
str1=replace(str1,","&item&",",",")
m=true
end if
next
if m then
while instr(str1,",,")>0
str1=replace(str1,",,",",")
wend
str1=left(str1,len(str1)-1)
str1=right(str1,len(str1)-1)
formatStr=str1
else
formatStr="字符串中不包含"&str2
end if
end function
%>

yyh112 2009-11-03
  • 打赏
  • 举报
回复
谢谢
hookee 2009-11-03
  • 打赏
  • 举报
回复

<%
n = "1,2,3,4,5,6,12,11,34,23,"
i = "1,11,3,4,13"

a = Split(n, ",")
Set dic = CreateObject("Scripting.Dictionary")
For k=0 To UBound(a)
If a(k)<> "" Then dic.Add "_" & a(k), a(k)
Next
a = Split(i, ",")
For k=0 To UBound(a)
If a(k)<> "" Then
If dic.Exists("_" & a(k)) Then
dic.Remove "_" & a(k)
Else
Response.Write a(k) & "不存在"
End If
End If
Next

items = dic.Items()
Set dic = Nothing
Response.Write "最后得到: " & Join(items, ",")
%>

28,406

社区成员

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

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