注册 登录
编程论坛 ASP技术论坛

Function 为什么不能这样调用?

kira007 发布于 2009-07-20 10:20, 574 次点击
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
3 回复
#2
yms1232009-07-20 14:33
不明白楼主写这个函数做什么用?想调用什么?
#3
kira0072009-07-20 18:05
字符串比较啊
比较 字符串1 和 字符串2
根据参数
得到比较结果
如:A=1,3,4
    B= 1,5,6
ADD-> 得到字符串A 比 字符串B 不同的新 字符串3,4
DEL-> 得到字符串B 比 字符串A 不同的新 字符串5,6
#4
yms1232009-07-20 18:49
这两个字符串允许长度不一样?
1