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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,235 questions

56,137 answers

573 users

How to remove all adjacent duplicate characters from a string until no more can be removed in VB.NET

1 Answer

0 votes
Imports System
				
Module Module1

    Function RemoveAdjacentDuplicates(s As String) As String
        Dim stack As New System.Text.StringBuilder()

        For Each ch As Char In s
            Dim n As Integer = stack.Length

            If n > 0 AndAlso stack(n - 1) = ch Then
                stack.Remove(n - 1, 1)   ' pop
            Else
                stack.Append(ch)         ' push
            End If
        Next

        Return stack.ToString()
    End Function

    Sub Main()
        Dim s As String = "abbacccada"
	
        Console.WriteLine(RemoveAdjacentDuplicates(s))  
    End Sub

End Module



' run
'
' cada
'

 



answered Mar 7 by avibootz

Related questions

...