For Programmers: Free Programming Magazines  


Home > Archive > Tcl > August 2004 > Re: [string totitle "ab cd ef"] does not output "Ab Cd Ef" but in









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [string totitle "ab cd ef"] does not output "Ab Cd Ef" but in
Jules

2004-08-27, 8:58 am

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 operating
> 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com