Duplicate Character Counter in Visual Basic

Published on 07 May 2026 (Updated: 07 May 2026)

Welcome to the Duplicate Character Counter in Visual Basic page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

Imports System.Text

Public Module DuplicateCharacterCounter

    Public Sub Main(args As String())

        If args.Length = 0 OrElse String.IsNullOrEmpty(args(0)) Then
            Console.WriteLine("Usage: please provide a string")
            Return
        End If

        Dim input As String = args(0)

        Dim countMap As New Dictionary(Of Char, Integer)

        For Each c As Char In input

            If countMap.ContainsKey(c) Then
                countMap(c) += 1
            Else
                countMap(c) = 1
            End If

        Next

        Dim result As New StringBuilder()
        Dim seen As New HashSet(Of Char)

        For Each c As Char In input

            If countMap(c) > 1 AndAlso Not seen.Contains(c) Then
                result.AppendLine($"{c}: {countMap(c)}")
                seen.Add(c)
            End If

        Next

        If result.Length = 0 Then
            Console.WriteLine("No duplicate characters")
        Else
            Console.WriteLine(result.ToString().TrimEnd())
        End If

    End Sub

End Module

Duplicate Character Counter in Visual Basic was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.