Home » , » TCL - String Subcommands - length index range

TCL - String Subcommands - length index range

Written By 1 on Monday, June 11, 2012 | 11:35 PM


Tcl commands often have "subcommands". The string command is an example of one of these. The string command treats its first argument as a subcommand. Utilizing subcommands is a good way to make one command do multiple things without using cryptic names. For instance, Tcl has string length instead of, say, slength.
This lesson covers these string subcommands:
string length string
Returns the length of string.
string index string index
Returns the indexth character from string.
string range string first last
Returns a string composed of the characters from first to last.

Example


set string "this is my test string"



uts "There are [string length $string] characters in \"$string\""

p

ts "[string index $string 1] is the second character in \"$string\""


p

uputs "\"[string range $string 5 10]\" are characters between the 5'th and 10'th"



0 Comment:

Post a Comment