标题:Function 为什么不能这样调用?
取消只看楼主
kira007
Rank: 2
等 级:论坛游民
帖 子:294
专家分:27
注 册:2007-6-28
结帖率:50%
已结贴  问题点数:20 回复次数:1 
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
搜索更多相关主题的帖子: Function 
2009-07-20 10:20
kira007
Rank: 2
等 级:论坛游民
帖 子:294
专家分:27
注 册:2007-6-28
得分:0 
字符串比较啊
比较 字符串1 和 字符串2
根据参数
得到比较结果
如:A=1,3,4
    B= 1,5,6
ADD-> 得到字符串A 比 字符串B 不同的新 字符串3,4
DEL-> 得到字符串B 比 字符串A 不同的新 字符串5,6

生活的理想,就是为了理想的生活。
2009-07-20 18:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-279868-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.170320 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved