加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[转载]转-tcl语法之 lindex用法

(2016-12-22 16:08:30)
标签:

转载

原文地址:转-tcl语法之 lindex用法作者:D_M_G







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} {} → 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

0

  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有