两个textbox中的文本一行一行比较,删除字符相同的行,代码怎么写
举例:text1             text2
    ________          _______
      123               123
      456               789
      000               000
运行之后,只保留456         789这一行

解决方案 »

  1.   

    dim i as integer
    dim temp1 as string
    dim temp2 as string
    on error resume next
    for i=0 to ubound(split(text1,vbcrlf))
        if split(text1,vbcrlf)(i)<>split(text2,vbcrlf)(i) then
            temp1=temp1 & split(text1,vbcrlf)(i) & vbcrlf
        endif
    next i
    for i=0 to ubound(split(text2,vbcrlf))
        if split(text2,vbcrlf)(i)<>split(text1,vbcrlf)(i) then
            temp2=temp2 & split(text2,vbcrlf)(i) & vbcrlf
        endif
    next i
    text1=temp1
    text2=temp2
      

  2.   

    每一行都有自己的项号item的,可以做比较呀,给你删除的算法吧
    Public Sub gLstDelItem(lstCtrl As Control, ByVal delIndex As Integer)
        If Not (TypeOf lstCtrl Is ListBox Or TypeOf lstCtrl Is ComboBox) Then
            Exit Sub
        End If
        
        If lstCtrl.ListCount > 0 And delIndex >= 0 Then
            lstCtrl.RemoveItem delIndex
            
            If lstCtrl.ListCount > 0 Then
                If lstCtrl.ListCount <= delIndex Then
                    lstCtrl.ListIndex = delIndex - 1
                Else
                    lstCtrl.ListIndex = delIndex
                End If
                
            End If
        End If
    End Sub
      

  3.   

    夏雪能不能请你把
    for i=0 to ubound(split(text1,vbcrlf))
        if split(text1,vbcrlf)(i)<>split(text2,vbcrlf)(i) then
            temp1=temp1 & split(text1,vbcrlf)(i) & vbcrlf
        endif
    next i
    这段代码解释一下
    谢了!
      

  4.   

    split(text1,vbcrlf)是把文本框里的文本按回车符分隔成数组,当然分隔符可以自己设定
    如果用split(text1),默认是空格,好像是!
    比如:text1="123 321 456"   那么执行temp=split(text1)结果是temp(1)="123" temp(2)="321" temp(3)="456"
    ubound是用来测试数组的下限的,比如上面的数组temp用ubound(temp)得到的值是3
    好像是这样的,如果没说清楚你去看看MSDN!
    BYE-BYE