tcl 相关语法
lindex:
语法:lindex list
index
返回list的第index个(0-based)元素。例:
% lindex {1 2 {3 4}}
2
3 4
名称
lindex - 从列表中获得一个元素
语法
lindexlist ?index...?
描述
lindex命令接受一个参数列表list,可以接受0个或者多个index参数,在多个参数的情况下,参数可以是单独的一次排列,也可以是在一个列表当中。
如果不指定index参数:
lindex list
或者
lindex list {}
这种情况下返回lindex列表本身。
当只有一个单独的元素时,lindex命令返回list列表中的第index个元素。替代时元素从0开始(也就是说索引0就是指列表的第一个元素),如果index是负数或者大于列表长度就返回一个空字符串。解释器在解释每一个index值时和string
index命令相同,都支持单个和多个index参数。
如果指定了多个index,将会选择列表的子列表中的元素。例如
lindex $a 1 2 3
或者
lindex $a {1 2 3}
与下面的命令相同
lindex [lindex [lindex $a 1] 2] 3
lindex {a b c}
{} → a b c
lindex {a b c}
0 → a
lindex {a b c}
2 → c
lindex {a b c}
end → c
lindex {a b c}
end-1 → b
lindex {{a b c} {d e f} {g h i}}
2 1 → h
lindex {{a b c} {d e f} {g h i}}
{2 1} → h
lindex {{{a b} {c d}} {{e f} {g
h}}} 1 1 0 → g
lindex {{{a b} {c d}} {{e f} {g
h}}} {1 1 0} → g
原文
http://hi.baidu.com/jakinweng?page=2
加载中,请稍候......