TCL自學(xué)筆記-18 lindex函數(shù)命令
tcl腳本-lindex函數(shù)
語(yǔ)法:lindex list indiex
例:
set a {1 2 3 4 5}
lindex a 2
3 //返回第三個(gè)元素
或者:lindex list {}
這種情況下返回 lindex列表本身。
當(dāng)只有一個(gè)單獨(dú)的元素時(shí),lindex命令返回list列表中的第index個(gè)元素。替代時(shí)元素從0開始(也就是說(shuō)索引0就是指列表的第一個(gè)元素),如果index是負(fù)數(shù)或者大于列表長(zhǎng)度就返回一個(gè)空字符串。解釋器在解釋每一個(gè)index值時(shí)和string index命令相同,都支持單個(gè)和多個(gè)index參數(shù)。
lindex {a b c}
→ a b cl
index {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
如果指定了多個(gè)index,將會(huì)選擇列表的子列表中的元素。例如:
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
set d [lindex $c 1 0 ]
{1 2 3} {3 2 3} {4 2 3}
(Documents) 400 % set d [lindex $c 1 0 ]
3
(Documents) 401 % set d [lindex $c 2 0 ]
4
工程師必備
- 項(xiàng)目客服
- 培訓(xùn)客服
- 平臺(tái)客服
TOP




















