Function 为什么不能这样调用?
oldstr="1|2"newstr="1"
addstr = CompareString(oldstr,newstr,"add")
'=================================================
'这个位置 输出 oldstr 或者 newstr 或 下面的调用 都会报错
'delstr = CompareString(oldstr,newstr,"del")
'只能单个调用
'除非加上 oldstr2=oldstr, newstr2= newstr
'把以上调用改为 delstr = CompareString(oldstr2,newstr2,"del")
'这样就可以 同时存在 addstr , delstr
'这是什么原因??
'=================================================
Function CompareString(str1,str2,action)
dim restring,sum
restring=""
sum=0
if action ="add" then
if Int(len(str1))=0 then
restring = str2
else
'=========================================================
str1=split(str1,"|")
str2=split(str2,"|")
for i=0 to ubound(str2)
for j=0 to ubound(str1)
if str2(i) = str1(j) then
exit for
else
sum = sum+1
end if
next
if(sum = ubound(str1)+1) then
restring = restring & str2(i) &"|"
end if
sum=0
next
'======================================================
if len(restring)>0 then
restring=left(restring,len(restring)-1)
end if
end if
else
if Int(len(str2))=0 then'新字符串为空
restring = str1 ' 返回原字符串 作为 删除字符
else
str1=split(str1,"|")
str2=split(str2,"|")
for i=0 to ubound(str1)
for j=0 to ubound(str2)
if str2(j) = str1(i) then
exit for
else
sum = sum+1
end if
next
if(sum = ubound(str2)+1) then
restring = restring & str1(i) &"|"
end if
sum=0
next
'======================================================
if len(restring)>0 then
restring=left(restring,len(restring)-1)
end if
end if
end if
'得出需要 增添的字符
CompareString = restring
End Function