1<HTML><HEAD><TITLE>Tcl Built-In Commands - lrange manual page</TITLE></HEAD><BODY>
2<H3><A NAME="M2">NAME</A></H3>
3lrange - Return one or more adjacent elements from a list
4<H3><A NAME="M3">SYNOPSIS</A></H3>
5<B>lrange </B><I>list first last</I><BR>
6<H3><A NAME="M4">DESCRIPTION</A></H3>
7<I>List</I> must be a valid Tcl list.  This command will
8return a new list consisting of elements
9<I>first</I> through <I>last</I>, inclusive.
10<I>First</I> or <I>last</I>
11may be <B>end</B> (or any abbreviation of it) to refer to the last
12element of the list.
13If <I>first</I> is less than zero, it is treated as if it were zero.
14If <I>last</I> is greater than or equal to the number of elements
15in the list, then it is treated as if it were <B>end</B>.
16If <I>first</I> is greater than <I>last</I> then an empty string
17is returned.
18Note: ``<B>lrange </B><I>list first first</I>'' does not always produce the
19same result as ``<B>lindex </B><I>list first</I>'' (although it often does
20for simple fields that aren't enclosed in braces); it does, however,
21produce exactly the same results as ``<B>list [lindex </B><I>list first</I><B>]</B>''
22<H3><A NAME="M5">EXAMPLES</A></H3>
23Selecting the first two elements:
24<PRE>% <B>lrange</B> {a b c d e} 0 1
25a b</PRE>
26<P>
27Selecting the last three elements:
28<PRE>% <B>lrange</B> {a b c d e} end-2 end
29c d e</PRE>
30<P>
31Selecting everything except the first and last element:
32<PRE>% <B>lrange</B> {a b c d e} 1 end-1
33b c d</PRE>
34<P>
35Selecting a single element with <B>lrange</B> is not the same as doing
36so with <B><A HREF="../TclCmd/lindex.htm">lindex</A></B>:
37<PRE>% set var {some {elements to} select}
38some {elements to} select
39% lindex $var 1
40elements to
41% <B>lrange</B> $var 1 1
42{elements to}</PRE>
43<H3><A NAME="M6">SEE ALSO</A></H3>
44<B><A HREF="../TclCmd/list.htm">list</A></B>, <B><A HREF="../TclCmd/lappend.htm">lappend</A></B>, <B><A HREF="../TclCmd/lindex.htm">lindex</A></B>, <B><A HREF="../TclCmd/linsert.htm">linsert</A></B>, <B><A HREF="../TclCmd/llength.htm">llength</A></B>, <B><A HREF="../TclCmd/lsearch.htm">lsearch</A></B>, <B><A HREF="../TclCmd/lset.htm">lset</A></B>, <B><A HREF="../TclCmd/lreplace.htm">lreplace</A></B>, <B><A HREF="../TclCmd/lsort.htm">lsort</A></B>
45<H3><A NAME="M7">KEYWORDS</A></H3>
46<A href="../Keywords/E.htm#element">element</A>, <A href="../Keywords/L.htm#list">list</A>, <A href="../Keywords/R.htm#range">range</A>, <A href="../Keywords/S.htm#sublist">sublist</A>
47<HR><PRE>
48<A HREF="../copyright.htm">Copyright</A> &#169; 1993 The Regents of the University of California.
49<A HREF="../copyright.htm">Copyright</A> &#169; 1994-1996 Sun Microsystems, Inc.
50<A HREF="../copyright.htm">Copyright</A> &#169; 2001 Kevin B. Kenny. All rights reserved.
51<A HREF="../copyright.htm">Copyright</A> &#169; 1995-1997 Roger E. Critchlow Jr.</PRE>
52</BODY></HTML>
53