TCL双引号 花括号 中括号

TCL的执行分为两步,第一步替换,第二步执行。。

在方括号[]中的内容将在替换步骤中计算出结果,整体替换为结果,类似于C中调用函数。方括号在反斜杠后或在花括号内无此作用。例子:

set b "\[set y {This is a string within braces within quotes}]"  ;#y值有更新

puts $b

输出。。[set y {This is a string within braces within quotes}]


set z {[set x {This is a string within quotes within braces}]} ;#x值有更新

puts $z

输出。。[set x {This is a string within quotes within braces}]


在双引号和花括号中的内容将视为一个参数

在双引号中的内容在替换步骤中,执行替换。。例如, puts "The current stock value is $varName"  中的varName将会被替换为varName的值。

大多在反斜杠后的内容表示不被替换。。如 \",但有一些反斜杠后的内容表示要被替换,如下表中内容。。但是如果一个反斜杠在行尾,表示下一行的内容和这行的内容是同一行,tcl将会用一个空格替换行尾的反斜杠。。

StringOutputHex Value
\aAudible Bell0x07
\bBackspace0x08
\fForm Feed (clear screen)0x0c
\nNew Line0x0a
\rCarriage Return0x0d
\tTab0x09
\vVertical Tab0x0b
\0ddOctal Valued is a digit from 0-7
\uHHHHH is a hex digit 0-9,A-F,a-f. This represents a 16-bit Unicode character.
\xHH....Hex ValueH is a hex digit 0-9,A-F,a-f. Note that the \x substitution "keeps going" as long as it has hex digits, and only uses the last two, meaning that \xaa and \xaaaa are equal, and that \xaaAnd anyway will "eat" the A of "And". Using the \u notation is probably a better idea.
花括号中的内容将不被替换,除了行尾的反斜杠。。但,据参考链接表示。expr后跟花括号,执行速度更快。i.e. expr {$i*10} 比expr $i*10快

双引号和花括号的这种用法只有当它们用来组织一个参数时才有作用。。例子:

set Z Albany
set Z_LABEL "The Capitol of New York is: "

puts "$Z_LABEL {$Z}"
puts {Who said, "What this country needs is a good $0.05 cigar!"?}
第一行输出。。The Capitol of New York is: {Albany}。。(引号已经起了组织一个参数的作用,故花括号不再起这种作用,作为普通字符)

第二行输出。。Who said, "What this country needs is a good $0.05 cigar!"?


参考链接:https://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值