1.binary format formatstring arg arg
binary format c3 {1 2 120}
这条命令返回一个二进制字符串,各字节为\x01\x02\x80,格式c3的意思是格式化三个8 位有符号整数
binary format I2a {1 -32 412534} E
格式指示符I2,只针对后面参数 {1 -32 412534}的开头两个数,因为该指示符的技术是2,会把这两个数作为32位有符号整数,按大端(最高有效字节在前)存放,第二个格式指示符a,从后面第二个参数中获取一个字符,存储为8位Latin-1字符
2.binary scan binarystring formatstring varname varname ...
binary scan 的返回值是该名利设置的变量的个数
set data "\x40\x41\x42\x43\x44\x45\x46\x47\x48"
binary scan $data a4c4 str chars
=>2
puts $str
=>@ABC
puts $chars
=> 68 69 70 71
3.lindex 至少获取两个参数,一个列表和一个索引值,end对应列表的最后一个元素,end-1对应倒数第二个
lindex {john anne mary jim} 1
=>anne
4.llength 返回列表中的元素的个数
llength {A b c d}
=> 4
set test1 {a b\ c d}
llength $test1
=>3
lindex {a b {c d e} f} 2
=>c d e
set element { {a b} {c {d e f}} g}
lindex $element 1 1 2
=>f
lindex $element { 0 0}
=>a
5.创建列表list,concat,lrepeat
list命令把它的参数假如列表,即每个参数作为列表的一个独立的元素
list {a b c} {d e} f {g h i}
=>{a b c} {d e} f {g h i}
提示:如果不知道元素的值是什么,使用list名利穿件列表是安全的方法(如提示用户进行输入,或从文件中读取一个值)
6.concat 接受任意多个列表作为参数,把列表参数中的所有元素串接为一个大的列表,如果某输入列表的某个元素是嵌套的列表,这个元素会保持为嵌套的列表。
concat {a b c} {d e} f {g h i}
=> a b c d e f g h i
concat {a b} {c {d e f}}
=>a b c {d e f}
set x {a b c}
set y {d e}
set z [concat $x $y]
=>a b c d e
concat 完成的任意可以用双引号来完成
set z "$x $y"
=> a b c d e
7.lrepeat 重复一个元素集合来创建列表,第一个参数指定重复的次数
lrepeat 3 a
=>a a a
lrepeat 4 a b c
=> a b c a b c a b c a b c
lrepeat 3 {a b} c
=> {a b} c {a b} c {a b} c
8.lrange返回列表中某范围类的元素,参数为一个列表和两个索引值
set x {a b {c d} e}
lrange $x 1 3
=>b {c d} e
9.linsert吧一个或多个元素插入已经存在的列表
set x {a b {c d} e}
linsert $x 2 X Y Z
=>a b X Y Z {c d} e
linsert $x 0 {X Y} Z
=>{X Y} Z a b {c d} e
10.lreplace 从列表中删除元素,第一个参数是列表,第二个和第三个参数给出要删除的那部分元素的开头和结尾元素的索引,如果只给定3个参数,那么结果就是从列表中删除指定的元素
lreplace { a b {c d} e} 3 3
=> a b {c d}
如果指定更多参数,这些参数会给插入被删除元素的位置
lreplace {a b {c d} e} 1 2 {w x} y z
=>a {w x} y z e