数组去除重复元素的VB.Net实现⽅法转载:www.smallbasic/thread-298-1-1.html
1. '数组去除重复元素的VB.Net实现⽅法
2. Dim stringArray As String() = {"aaa", "bbb", "aaa", "ccc", "bbb", "ddd", _
3.        "ccc", "aaa", "bbb", "ddd"}
4. 'List⽤于存储从数组⾥取出来的不相同的元素
5. Dim listString As New List(Of String)()
6. For Each eachString As String In stringArray
7.        If Not listString.Contains(eachString) Then
8.                listString.Add(eachString)
9.        End If
10. Next
vb 字符串转数组11. '最后从List⾥取出各个字符串进⾏操作
12. For Each eachString As String In listString
13.                '打印每个字符串
14.        Console.Write(eachString)
15. Next
复制代码
1. Dim stest As String() = New String() {"aaa", "bbb", "ccc", "aaa", "ccc"}
2. Dim list As New ArrayList()
3. For i As Integer = 0 To stest.Length - 1
4.        Dim IsExist As Boolean = True
5.        For j As Integer = 0 To list.Count - 1
6.                If list(j).ToString() = stest(i) Then
7.                        IsExist = False
8.                        Exit For
9.                End If
10.        Next
11.        If IsExist Then
12.                list.Add(stest(i))
13.        End If
14. Next
复制代码
1. If Not list.Contains(stest(i)) Then
2.        list.Add(stest(i))
3. End If
复制代码

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。