string(n) Tcl Built-In Commands string(n) _________________________________________________________________ NAME string - Manipulate strings SYNOPSIS string _o_p_t_i_o_n _a_r_g ?_a_r_g ...? _________________________________________________________________ DESCRIPTION Performs one of several string operations, depending on _o_p_t_i_o_n. The legal _o_p_t_i_o_ns (which may be abbreviated) are: string compare _s_t_r_i_n_g_1 _s_t_r_i_n_g_2 Perform a character-by-character comparison of strings _s_t_r_i_n_g_1 and _s_t_r_i_n_g_2 in the same way as the C strcmp procedure. Return -1, 0, or 1, depending on whether _s_t_r_i_n_g_1 is lexicographically less than, equal to, or greater than _s_t_r_i_n_g_2. string first _s_t_r_i_n_g_1 _s_t_r_i_n_g_2 Search _s_t_r_i_n_g_2 for a sequence of characters that exactly match the characters in _s_t_r_i_n_g_1. If found, return the index of the first character in the first such match within _s_t_r_i_n_g_2. If not found, return -1. string index _s_t_r_i_n_g _c_h_a_r_I_n_d_e_x Returns the _c_h_a_r_I_n_d_e_x'th character of the _s_t_r_i_n_g argu- ment. A _c_h_a_r_I_n_d_e_x of 0 corresponds to the first char- acter of the string. If _c_h_a_r_I_n_d_e_x is less than 0 or greater than or equal to the length of the string then an empty string is returned. string last _s_t_r_i_n_g_1 _s_t_r_i_n_g_2 Search _s_t_r_i_n_g_2 for a sequence of characters that exactly match the characters in _s_t_r_i_n_g_1. If found, return the index of the first character in the last such match within _s_t_r_i_n_g_2. If there is no match, then return -1. string length _s_t_r_i_n_g Returns a decimal string giving the number of charac- ters in _s_t_r_i_n_g. string match _p_a_t_t_e_r_n _s_t_r_i_n_g See if _p_a_t_t_e_r_n matches _s_t_r_i_n_g; return 1 if it does, 0 if it doesn't. Matching is done in a fashion similar to that used by the C-shell. For the two strings to match, their contents must be identical except that the following special sequences may appear in _p_a_t_t_e_r_n: Tcl Last change: 7.6 1 string(n) Tcl Built-In Commands string(n) * Matches any sequence of characters in _s_t_r_i_n_g, including a null string. ? Matches any single character in _s_t_r_i_n_g. [_c_h_a_r_s] Matches any character in the set given by _c_h_a_r_s. If a sequence of the form _x-_y appears in _c_h_a_r_s, then any character between _x and _y, inclusive, will match. \_x Matches the single character _x. This pro- vides a way of avoiding the special interpre- tation of the characters *?[]\ in _p_a_t_t_e_r_n. string range _s_t_r_i_n_g _f_i_r_s_t _l_a_s_t Returns a range of consecutive characters from _s_t_r_i_n_g, starting with the character whose index is _f_i_r_s_t and ending with the character whose index is _l_a_s_t. An index of 0 refers to the first character of the string. An index of end (or any abbreviation of it) refers to the last character of the string. If _f_i_r_s_t is less than zero then it is treated as if it were zero, and if _l_a_s_t is greater than or equal to the length of the string then it is treated as if it were end. If _f_i_r_s_t is greater than _l_a_s_t then an empty string is returned. string tolower _s_t_r_i_n_g Returns a value equal to _s_t_r_i_n_g except that all upper case letters have been converted to lower case. string toupper _s_t_r_i_n_g Returns a value equal to _s_t_r_i_n_g except that all lower case letters have been converted to upper case. string trim _s_t_r_i_n_g ?_c_h_a_r_s? Returns a value equal to _s_t_r_i_n_g except that any leading or trailing characters from the set given by _c_h_a_r_s are removed. If _c_h_a_r_s is not specified then white space is removed (spaces, tabs, newlines, and carriage returns). string trimleft _s_t_r_i_n_g ?_c_h_a_r_s? Returns a value equal to _s_t_r_i_n_g except that any leading characters from the set given by _c_h_a_r_s are removed. If _c_h_a_r_s is not specified then white space is removed (spaces, tabs, newlines, and carriage returns). string trimright _s_t_r_i_n_g ?_c_h_a_r_s? Returns a value equal to _s_t_r_i_n_g except that any trail- ing characters from the set given by _c_h_a_r_s are removed. If _c_h_a_r_s is not specified then white space is removed (spaces, tabs, newlines, and carriage returns). Tcl Last change: 7.6 2 string(n) Tcl Built-In Commands string(n) string wordend _s_t_r_i_n_g _i_n_d_e_x Returns the index of the character just after the last one in the word containing character _i_n_d_e_x of _s_t_r_i_n_g. A word is considered to be any contiguous range of alphanumeric or underscore characters, or any single character other than these. string wordstart _s_t_r_i_n_g _i_n_d_e_x Returns the index of the first character in the word containing character _i_n_d_e_x of _s_t_r_i_n_g. A word is con- sidered to be any contiguous range of alphanumeric or underscore characters, or any single character other than these. KEYWORDS case conversion, compare, index, match, pattern, string, word Tcl Last change: 7.6 3