lindex.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
- '"
- '" Copyright (c) 1993 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '" Copyright (c) 2001 by Kevin B. Kenny. All rights reserved.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: lindex.n,v 1.7.4.1 2004/10/27 12:52:40 dkf Exp $
- '"
- .so man.macros
- .TH lindex n 8.4 Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- lindex - Retrieve an element from a list
- .SH SYNOPSIS
- fBlindex fIlist ?index...?fR
- .BE
- .SH DESCRIPTION
- .PP
- .VS 8.4
- The fBlindexfP command accepts a parameter, fIlistfP, which
- it treats as a Tcl list. It also accepts zero or more fIindicesfP into
- the list. The indices may be presented either consecutively on the
- command line, or grouped in a
- Tcl list and presented as a single argument.
- .PP
- If no indices are presented, the command takes the form:
- .CS
- lindex list
- .CE
- or
- .CS
- lindex list {}
- .CE
- In this case, the return value of fBlindexfR is simply the value of the
- fIlistfR parameter.
- .PP
- When presented with a single index, the fBlindexfR command
- treats fIlistfR as a Tcl list and returns the
- .VE
- fIindexfR'th element from it (0 refers to the first element of the list).
- In extracting the element, fBlindexfR observes the same rules
- concerning braces and quotes and backslashes as the Tcl command
- interpreter; however, variable
- substitution and command substitution do not occur.
- If fIindexfR is negative or greater than or equal to the number
- of elements in fIvaluefR, then an empty
- string is returned.
- If fIindexfR has the value fBendfR, it refers to the last element
- in the list, and fBend-fIintegerfR refers to the last element in
- the list minus the specified integer offset.
- .PP
- .VS 8.4
- If additional fIindexfR arguments are supplied, then each argument is
- used in turn to select an element from the previous indexing operation,
- allowing the script to select elements from sublists. The command,
- .CS
- lindex $a 1 2 3
- .CE
- or
- .CS
- lindex $a {1 2 3}
- .CE
- is synonymous with
- .CS
- lindex [lindex [lindex $a 1] 2] 3
- .CE
- .SH EXAMPLES
- .CS
- fBlindexfR {a b c} fI=> a b cfR
- fBlindexfR {a b c} {} fI=> a b cfR
- fBlindexfR {a b c} 0 fI=> afR
- fBlindexfR {a b c} 2 fI=> cfR
- fBlindexfR {a b c} end fI=> cfR
- fBlindexfR {a b c} end-1 fI=> bfR
- fBlindexfR {{a b c} {d e f} {g h i}} 2 1 fI=> hfR
- fBlindexfR {{a b c} {d e f} {g h i}} {2 1} fI=> hfR
- fBlindexfR {{{a b} {c d}} {{e f} {g h}}} 1 1 0 fI=> gfR
- fBlindexfR {{{a b} {c d}} {{e f} {g h}}} {1 1 0} fI=> gfR
- .CE
- .VE
- .SH "SEE ALSO"
- list(n), lappend(n), linsert(n), llength(n), lsearch(n),
- .VS 8.4
- lset(n),
- .VE
- lsort(n),
- lrange(n), lreplace(n)
- .SH KEYWORDS
- element, index, list