A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
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.
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.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.