以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请教集合  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=89410)

--  作者:hbhb
--  发布时间:2016/8/21 12:15:00
--  请教集合
大师:请教代码
一个数组{“a”,"b","ab","bc","a","b")} 如何求出数组中元素出现一次的集合?

--  作者:y2287958
--  发布时间:2016/8/21 12:48:00
--  
Dim ary() As String = {"a","b","ab","bc","a","b"}
Dim lst1,lst2 As new List(of String)
For Each s As String In ary
    If lst1.Contains(s)
        lst2.Add(s)
    Else
        lst1.Add(s)
    End If
Next
For Each s As String In lst2
    lst1.Remove(s)
Next
Output.Show(String.Join("/",lst1.ToArray))

--  作者:hbhb
--  发布时间:2016/8/21 13:09:00
--  
谢谢!那如果求重复字符呢?
--  作者:大红袍
--  发布时间:2016/8/21 13:26:00
--  

Dim ary() As String = {"a","b","ab","bc","a","b"}
Dim dic As new Dictionary(Of String, Integer)
For Each s As String In ary
    If dic.ContainsKey(s) = False Then
        dic.Add(s, 1)
    Else
        dic(s) = dic(s) + 1
    End If
Next

For Each k As String In dic.Keys
    If dic(k) > 1 Then
        output.show(k)
    End If
Next


--  作者:hbhb
--  发布时间:2016/8/21 16:07:00
--  
中国女排!!!