您的位置:首页 > 其它

关于字符串的处理

2007-12-21 13:45 239 查看
str1="中文1,中文2,中文3,中文4,中文5,中文6"
str2="num1,mun2,num3,num4,num5,num6"

上面两个字符串是对应的:
num1对应着中文1
num2对应着中文2
num3对应着中文3
........................

str3="num3,num5"

如何根据上面的三个字符串得到
str4="中文3,中文5"
str5="中文1,中文2,中文4,中文6,"

--------------------------------------------------------------------------------------------------

dim str1,str2,str3,str4,str5
str1 = "中文1,中文2,中文3,中文4,中文5,中文6"
str2 = "num1,num2,num3,num4,num5,num6"

'type参数是搜索str3在str1或者str2,1是在str1,2是在str2
function getSplit(str3,ReType)
str4="":str5=""
dim ss1,ss2,ss3,i,index
ss1=split(str1,",")
ss2=split(str2,",")
ss3=split(str3,",")
for i=0 to ubound(ss3)
if ReType=1 then
index=getIndex(ss1,ss3(i))
if index<>-1 then
str5=str5&","&ss2(index)
ss2(index)=""'消除这个的值
end if
else
index=getIndex(ss2,ss3(i))
if index<>-1 then
str5=str5&","&ss1(index)
ss1(index)=""
end if
end if
next

if ReType=1 then
for each s in ss2
if s<>"" then str4=str4&","&s
next
else
for each s in ss1
if s<>"" then str4=str4&","&s
next
end if
str4=right(str4,len(str4)-1)
str5=right(str5,len(str5)-1)
end function

'获取ss3中的值在ss1或者ss2中的下标位置
function getIndex(ss,Value)
dim k
for k=0 to ubound(ss)
if ss(k)=Value then
getIndex=k
exit function
end if
next
getIndex=-1
end function

getSplit "num3,num5",2
response.Write "str4="""&str4&"""<br/>"
response.Write "str5="""&str5&"""<br/>"

response.Write "<br/>"

getSplit "中文3,中文5",1
response.Write "str4="""&str4&"""<br/>"
response.Write "str5="""&str5&"""<br/>"

----------------------------------------------------------------------------

http://topic.csdn.net/u/20071220/22/33b8dddb-f6da-4417-a95c-e05060e3c527.html?seed=977250335
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: