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. ...

Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.