Converting a string to title
The second keyword that Tcl provides to alter the case of a string is totitle
. As its name implies, the totitle
keyword returns a string with the first Unicode character capitalized.
The syntax of the string
command is as follows:
string totitle string first last
When invoked with the totitle
keyword the string
command will convert the value stored in string
to its title equivalent.
How to do it…
In the following example, we will convert a string that contains only lowercase characters to its title case. Return values from the commands are provided for clarity. Enter the following command:
% string totitle "john" John
How it works…
The title
command converts the first character of a string to its Unicode title case variant. If no title variant exists, it is converted to uppercase. If an optional index value is passed in the first
location, the conversion will commence at that location. If an index value is passed in the last
location, this will designate the location...