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