Returning a range of characters from a string
It is not uncommon to cut a string into its constituent parts. This allows the data to be stored in-line, without comma or space separation, thereby, minimizing the impact on the disk storage. To assist us in this, and other instances where we need to extract a range of characters from a string, Tcl has provided the range
keyword.
The syntax of the string
command is as follows:
string range string first last
When invoked with the range
keyword, the string
command will return all characters inclusive between those specified in the first
and last
location.
How to do it…
In the following example we will locate a range of characters contained within a string. Return values from the commands are provided ...
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.