以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何得到不重复序列  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=64519)

--  作者:chnfo
--  发布时间:2015/2/17 10:16:00
--  [求助]如何得到不重复序列
有一个字符串1.2.3,1.2.4,1.7,2.8.1……,如何得到1,1.2,1.2.3,1.2.4,1.7,2,2.8,2.8.1这样的包含它及它的上级的不重复的序到?
--  作者:黄训良
--  发布时间:2015/2/17 14:44:00
--  
Tables("表A").Filter = "[第一列] like \'1.2%\'"
--  作者:有点甜
--  发布时间:2015/2/23 10:19:00
--  

 去重复?参考代码

 

Dim str As String = "2.4,1.7,1,1.2,1.2.3,1,1.2,1.2.4,1.7,2,2.8,2.8.1,2,2.8,2.8.1"
Dim ls As New List(Of String)
For Each s As String In str.Split(",")
    If ls.Contains(s) = False Then
        ls.Add(s)
    End If
Next
Dim ary As array = ls.ToArray
Array.Sort(ary)
output.show(String.Join(",", ary))


--  作者:chnfo
--  发布时间:2015/2/25 10:21:00
--  
甜兄年过得好啊。我的意思没表达到位,要将1.2.4分解成1,1.2,1.2.4,将1.2.3分解成1,1.2,1.2.3,合并后再去重
--  作者:有点甜
--  发布时间:2015/2/25 10:26:00
--  
Dim str As String = "2.4,1.7,1,1.2,1.2.3,1,1.2,1.2.4,1.7,2,2.8,2.8.1,2,2.8,2.8.1"
Dim ls As New List(Of String)
For Each ss As String In str.Split(",")
    Dim temp As String = ""
    For Each s As String In ss.Split(".")
        temp = iif(temp = "", s, temp & "." & s)
        If ls.Contains(temp) = False Then
            ls.Add(temp)
        End If
    Next
Next
Dim ary As array = ls.ToArray
Array.Sort(ary)
output.show(String.Join(",", ary))