Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,919 questions

51,852 answers

573 users

How to remove non-duplicate characters from string in VB.NET

1 Answer

0 votes
Imports System
Imports System.Text
Imports System.Collections.Generic

Public Class Program
    Public Shared Function removeNonDuplicate(ByVal str As String) As String
        Dim arr As Char() = str.ToCharArray()
        Dim duplicateList As IList(Of Char) = New List(Of Char)()

        For Each ch As Char In arr
            If str.IndexOf(ch) <> str.LastIndexOf(ch) Then
                duplicateList.Add(ch)
            End If
        Next

        Dim duplicateString As StringBuilder = New StringBuilder()

        For Each ch As Char In duplicateList
            duplicateString.Append(ch)
        Next

        Return duplicateString.ToString()
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim str As String = "Bubble Occurrence Mammal vb"
        Console.WriteLine(removeNonDuplicate(str))
    End Sub
End Class




' run:
'
' ubble ccurrece ammal b
'


 



answered Mar 20, 2024 by avibootz

Related questions

2 answers 186 views
3 answers 242 views
1 answer 102 views
3 answers 180 views
1 answer 217 views
2 answers 214 views
...