Duplicate Character Counter in Tcl

Published on 08 October 2025 (Updated: 08 October 2025)

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

Current Solution

proc usage {} {
	puts stderr "Usage: please provide a string"
	exit 1
}

proc countDuplicates {str} {
	set counts [dict create]
	set order {}

	foreach ch [split $str {}] {
		if {[string is alnum -strict $ch]} {
			if {![dict exists $counts $ch]} {
				lappend order $ch
			}
			dict incr counts $ch 1
		}
	}

	set printed 0

	foreach ch $order {
		set count [dict get $counts $ch]
		if {$count > 1} {
			puts "$ch: $count"
			incr printed
		}
	}

	if {$printed == 0} {
		puts "No duplicate characters"
	}
}

if {$argc != 1} { usage }

set input [string trim [lindex $argv 0]]
if {$input eq ""} { usage }

countDuplicates $input


Duplicate Character Counter in Tcl 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.