以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  找出两个字符串的差异  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=60272)

--  作者:qianqian1530
--  发布时间:2014/11/21 13:16:00
--  找出两个字符串的差异
Dim des As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7"
Dim des1 As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7,530"


怎么才能 删除两个字符串 相同值呢?

结果 应该是 530 

--  作者:飞飞
--  发布时间:2014/11/21 13:18:00
--  
 replace(\'acb\',\'a\',\'\')
结果 cb

--  作者:qianqian1530
--  发布时间:2014/11/21 13:30:00
--  
没那么简单...
--  作者:jialihaha
--  发布时间:2014/11/21 13:57:00
--  
Dim des As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7"
Dim des1 As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7,530"

MessageBox.Show(des1.Replace(des,"").Remove(0,1)) 
你看看是不是这样?

--  作者:qianqian1530
--  发布时间:2014/11/21 14:02:00
--  
也不是哦, 

Dim des As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7"
Dim des1 As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7,530"

只是单纯的为了方便 复制后添加 530的···

des 和 des1 可能不同的数字 会更多...

我的思路是, 分割后 一个个对比, 但·· 不是那么顺利..

--  作者:Bin
--  发布时间:2014/11/21 14:23:00
--  

[此贴子已经被作者于2014-11-21 14:28:15编辑过]

--  作者:有点甜
--  发布时间:2014/11/21 14:23:00
--  

Dim des1 As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7"
Dim des2 As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7,530"
Dim ary1() As String = des1.Split(",")
Dim ary2() As String = des2.Split(",")
Dim ls As new List(Of String)
For Each s As String In ary2
    If array.IndexOf(ary1, s) < 0 AndAlso ls.Contains(s) = False Then
        ls.Add(s)
    End If
Next

For Each s As String In ary1
    If array.IndexOf(ary2, s) < 0 AndAlso ls.Contains(s) = False Then
        ls.Add(s)
    End If
Next

msgbox(String.Join(",",ls.ToArray))


--  作者:Bin
--  发布时间:2014/11/21 14:30:00
--  
Dim des As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7"
Dim des1 As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7,666"
Dim List1 As new List(of String)
Dim List2 As new List(of String)
List1.AddRange(des.split(","))
List2.AddRange(des1.split(","))
For i As Integer = List1.count-1 To 0 Step -1
    If List2.Contains(List1(i)) Then
        List2.Remove(List1(i))
        List1.Remove(List1(i))
    End If
Next
Dim List3 As new List(of String)
List3.AddRange(List1.ToArray())
List3.AddRange(List2.ToArray())
For Each s As String In List3
    output.show(s)
Next

[此贴子已经被作者于2014-11-21 14:36:53编辑过]

--  作者:jialihaha
--  发布时间:2014/11/21 14:42:00
--  

Dim des As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7"
Dim des1 As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7,530"

Dim desArr() As String
desArr= des.Split(",")


For Index As Integer = 0 To desArr.Length - 1
    
    If des1.Contains(desArr(Index)) Then
        If des1.Chars(des1.IndexOf(desArr(Index))+desArr(Index).Length)="," Then
            des1 = des1.Remove(des1.IndexOf(desArr(Index)),desArr(Index).Length+1)
        Else
            des1 = des1.Remove(des1.IndexOf(desArr(Index)),desArr(Index).Length)
        End If
    End If
    
Next
Output.Show(des1)

--  作者:lsy
--  发布时间:2014/11/21 17:31:00
--  
Dim str As String = "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7,530"
For Each s As String In "1,2,1,1,1,1,1,1,3,53,53,53,53,53,5,5,56,7".Split(",")
    Dim i As Integer = Array.IndexOf(str.Split(","),s)
    If i > - 1 Then
        str = str.Remove(i,s.Length)
    End If    
Next
MessageBox.Show(str.Replace(",",""))