## Tcl9.0.3/Tk9.0.3 Documentation > Tcl Commands > lrange

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

lrange — リストから一つ或はそれ以上の隣接した要素を返す Return one or more adjacent elements from a list

### 構文 SYNOPSIS

lrange list first last

### 説明 DESCRIPTION

リスト list は適法のTcl リストでなければならない｡この命令は､first から last 迄の両端を含む範囲の要素で構成される新しいリストを返す｡位置を指す値 first と last は､ string index 命令の為の指定値と同じに解釈され､単純算術指定とリスト末尾相対指定に対応している｡もし､ first が零より小さいと零として扱われる｡もし､ last がリスト中の要素の個数と同じか大きいと end として扱われる｡もし､ first が last よりも大きいと､空文字列が返される｡ List must be a valid Tcl list. This command will return a new list consisting of elements first through last, inclusive. The index values first and last are interpreted the same as index values for the command string index, supporting simple index arithmetic and indices relative to the end of the list. If first is less than zero, it is treated as if it were zero. If last is greater than or equal to the number of elements in the list, then it is treated as if it were end. If first is greater than last then an empty string is returned.

註意: “lrange list first first” は “lindex list first”と常に同じ結果を産出するとは限らない(但し､波括弧で括られない単純な対象では同じになることが多い); “list [lindex list first]” とは正確に同じ結果になる｡ Note that “lrange list first first” does not always produce the same result as “lindex list first” (although it often does for simple fields that are not enclosed in braces); it does, however, produce exactly the same results as “list [lindex list first]”

### 用例 EXAMPLES

最初の二つの要素を選択する: 　　　 Selecting the first two elements:

    % lrange {a b c d e} 0 1
    a b

最後の三つの要素を選択する: 　　　　 Selecting the last three elements:

    % lrange {a b c d e} end-2 end
    c d e

最初と最後を除き全ての要素を選択する: 　　　　 Selecting everything except the first and last element:

    % lrange {a b c d e} 1 end-1
    b c d

lrange により一個の要素を選び出す事と､lindexでそうする事とは同じではない: 　 Selecting a single element with lrange is not the same as doing so with lindex:

    % set var {some {elements to} select}
    some {elements to} select
    % lindex $var 1
    elements to
    % lrange $var 1 1
    {elements to}

### SEE ALSO

list, lappend, lassign, ledit, lindex, linsert, llength, lmap, lpop, lremove, lrepeat, lreplace, lreverse, lsearch, lseq, lset, lsort, string

### KEYWORDS

element, list, range, sublist
Copyright © 1993 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.
Copyright © 2001 Kevin B. Kenny <kennykb(at)acm.org>. All rights reserved.