'how to find the count of Uppercase and lowercase letters in TCL
how to find the count of uppercase amd lower case in tcl with this code im getting only ascii values
foreach character {H e l l o T C L} {
scan $character %c numeric
puts "ASCII character '$numeric' displays as '$character'."
}
Solution 1:[1]
Instead of looping through a string yourself, you can use regexp to give you a count:
set str "Hello Tcl"
puts "Uppercase: [regexp -all {[[:upper:]]} $str]"
puts "Lowercase: [regexp -all {[[:lower:]]} $str]"
I'm using [[:upper:]] and [[:lower:]] instead of [A-Z] and [a-z] because the former will correctly capture unicode upper- and lowercase, rather than just the ones in the ASCII set.
Solution 2:[2]
You can test each character with string is upper $character and string is lower $character. Note that non-alphabetic characters are neither upper or lower case. For more info check the documentation at https://www.tcl-lang.org/man/tcl8.6/TclCmd/string.htm#M10
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Schelte Bron |
| Solution 2 | Colin Macleod |
