Creating a string of repeated characters
Why would you need to create a string of identical characters? For example, to create a tabbed layout and you can't set/use tabs. To accomplish this and more Tcl has provided the repeat
keyword to do this programmatically and saved us hours of work in the process.
The syntax of the string
command is as follows:
string repeat strRepeat count
The string
command will create a string containing strRepeat
repeated count
times.
How to do it…
In the following example we will create a string containing five identical characters. Return values from the commands are provided for clarity. Enter the following command:
% string repeat x 5 xxxxx
How it works…
As you can see, Tcl has created our string of five x characters.