Version 1 of string totitle

Updated 2005-07-18 17:17:52 by LES

string totitle string ?first? ?last?

Returns a value equal to string except that the first character in string is converted to its Unicode title case variant (or upper case if there is no title case variant) and the rest of the string is converted to lower case. If first is specified, it refers to the first char index in the string to start modifying. If last is specified, it refers to the char index in the string to stop at (inclusive). First and last may be specified as for the index method.


LES on July 18 2005: I made a little script to fix music file names, so that "foo bar.ogg" becomes "Foo Bar.ogg", for example. I do that with a foreach loop, checking conditions on each word and modifying them accordingly with string totitle. The loop helps me keep certain words untouched. I provided a few "noise words", so that "foo of the bar.ogg" becomes "Foo of the Bar.ogg". Great.

Now I just ran into this file named "foo bar (last act).ogg", and it becomes "Foo Bar (last Act).ogg". Of course, "(last" is not modified as I had expected because its first character is the parenthesis.

Does anyone here think that the string totitle command should handle that kind of exception on its own? Like, say...

 string totitle -ignore {( ) [ ] \{ \} " ' # @ & *} $string

... so that all these characters would be ignored if in the beginning of a word and so that the first actual letter is uppercased?


See also:


Tcl syntax help - Category Command