Code Comments
Programming Forum and web based access to our favorite programming groups.Bruce Hartweg <bruce-news@hartweg.us> wrote in message news:<%gyXc.322037$%_
6.194545@attbi_s01>...
> you need/want something that is parsing the string into words and operatin
g
> on them individually. You could do this with a regsub/subst pair ...
>
> proc multiWordTitleCase {str} {
> subst [regsub -all {\w+} $str {[string totitle "&"]}]
> }
>
> Bruce
Isn't this code faster and more accurate:
proc wordsToTitle {str} {
foreach word $str {lappend output [string totitle $word]}
return $output
}
On tcl/tk 8.4.6.1 on win2k:
(bin) 62 % set test "it's a test"
it's a test
(bin) 63 % multiWordTitleCase $test
It'S A Test
(bin) 64 % wordsToTitle $test
It's A Test
(bin) 65 % time {multiWordTitleCase $test} 10000
55 microseconds per iteration
(bin) 66 % time {wordsToTitle $test} 10000
10 microseconds per iteration
--
Gilbert van Griensven
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.