:TITLE: String Subcommands - length index range ;# ;# RCSID: $Header: /cvsroot/tcl/tcltutorial/original/Tcl17.lsn,v 1.1 2004/11/04 16:01:13 davidw Exp $ ;# Copyright (c) 1995 Clif Flynt ;# 9300 Fleming Rd. ;# Dexter, MI 48130 ;# clif@cflynt.com ;# See file "NOTICE" for licensing terms. ;# :LESSON_TEXT_START_LEVEL 0: One feature of Tcl is that commands may have subcommands. String is an example of one of these. The string command treats the first argument as a subcommand. This lesson covers these string subcommands:
string length string
Returns the length of string
string index string index
Returns the char at the index'th position in string
string range string first last
Returns a string composed of the characters from first to last
:TEXT_END: :LESSON_TEXT_START_LEVEL 1: One feature of Tcl is that commands may have subcommands. String is an example of one of these. The string command treats the first argument as a subcommand. This lesson covers these string subcommands:
string length string
Returns the length of string
string index string index
Returns the char at the index'th position in string
string range string first last
Returns a string composed of the characters from first to last
:TEXT_END: :LESSON_TEXT_START_LEVEL 2: The string is one of the other trivial data structures in Tcl. Like the list, it is just a set of characters grouped in a single unit. Unlike the list, there is no structure to a string larger than a single character.

Tcl commands may have subcommands. Manipulating strings is done with a set of subcommands of the string command. The string command treats the first argument as a subcommand and performs the operation requested.

This set of string commands returns portions or information about a string.

This lesson covers these string subcommands:

string length string
Returns the length of string in characters.
string index string index
Returns the character at the index'th position in string
string range string first last
Returns a string composed of the characters from first to last
:TEXT_END: :CODE_START: set string "this is my test string" puts "There are [string length $string] characters in \"$string\"" puts "[string index $string 1] is the second character in \"$string\"" puts "\"[string range $string 5 10]\" are characters between the 5'th and 10'th" :TEXT_END: