CamelCase in Tcl
Example for versions
ActiveTcl 8.5,
JTcl 2.1.0,
Tcl 8.4,
Tcl 8.5.7
This example shows character-wise string processing. A regular expression is used to check whether current character is a letter.
set S [gets stdin]
set S [string tolower $S]
set L [string length $S]
set lastSpace 1
set cc ""
for {set i 0} {$i < $L} {incr i} {
set letter [string index $S $i]
if { [string match {[a-z]} $letter] } {
if { $lastSpace == 1 } { set letter [string toupper $letter] }
append cc $letter
set lastSpace 0
} else {
set lastSpace 1
}
}
puts $cc
Comments
]]>blog comments powered by Disqus
]]>