Creating a reverse string
There have been instances in the past where I had the need to reverse the characters I had received from the user input. To assist us in creating a reverse string, Tcl provides the reverse
keyword.
The syntax of the string command is as follows:
string reverse string
The string
command returns the value stored in string
in reverse order.
Getting ready
To complete the following example, we will need to access Tcl from the command line. Launch the Tcl shell appropriately for your operating system and follow the given instructions.
How to do it…
In the following example, we will create a string that is the reverse of the original. Return values from the commands are provided for clarity. Enter the following command:
% string reverse abc cba
How it works…
Tcl returns a string containing the original string provided in a reverse order.