Converting a string to uppercase
The third keyword that Tcl provides to alter the case of a string is toupper
. As its name implies, the toupper
keyword returns a string set to all uppercase characters.
The syntax of the string
command is as follows:
string toupper string first last
The string
command will convert all lowercase characters in a string 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 at which the conversion will stop.
How to do it…
In the following example, we will convert a string that contains only lowercase characters to uppercase. Return values from the commands are provided for clarity. Enter the following command:
% string toupper "now is the time" NOW IS THE TIME
How it works…
Tcl returns the entire string converted to its uppercase value.