Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19912390
  • 博文数量: 679
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 9308
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-18 10:51
文章分类

全部博文(679)

文章存档

2012年(5)

2011年(38)

2010年(86)

2009年(145)

2008年(170)

2007年(165)

2006年(89)

分类:

2011-03-17 10:27:35

                        §5     命令分析与置换1:使用""分组参数

#承接软件自动化实施与培训等gtalk: ouyangchongwu#gmail.com qq 37391319
#python qq group: 深圳自动化测试python群:113938272
#武冈深圳qq群:66250781

TCL中,命令的计算分为2个阶段。第一阶段仅仅是替换,第2阶段计算命令的值。只替换一次。

 

            比如在puts $varName puts "Hello World"中,就是先把varName置换为”Hello World”,然后再输出。

TCL提供三种形式的置换:变量置换、命令置换和反斜杠置换。上面的例子就是变量置换

            []中置换为命令的执行结果。

转义字符的置换

String             Output              Hex Value

\a        Audible Bell      0x07

\b       Backspace          0x08

\f        Form Feed (clear screen)             0x0c

\n       New Line          0x0a

\r        Carriage Return 0x0d

\t        Tab       0x09

\v       Vertical Tab       0x0b

\0dd    Octal Value        d is a digit from 0-7

\uHHHH         H is a hex digit 0-9,A-F,a-f. This represents a 16-byte Unicode character.

\xHH....          Hex Value          H 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.

 

位于行尾的\ 用于续行。

 

实例:

 

set Z Albany

set Z_LABEL "The Capitol of New York is: "

 

puts "$Z_LABEL $Z"   ;# Prints the value of Z

puts "$Z_LABEL \$Z"  ;# Prints a literal $Z instead of the value of Z

 

puts "\nBen Franklin is on the \$100.00 bill"

 

set a 100.00

puts "Washington is not on the $a bill"    ;# This is not what you want

puts "Lincoln is not on the $$a bill"      ;# This is OK

puts "Hamilton is not on the \$a bill"     ;# This is not what you want

puts "Ben Franklin is on the \$$a bill"    ;# But, this is OK

 

puts "\n................. examples of escape strings"

puts "Tab\tTab\tTab"

puts "This string prints out \non two lines"

puts "This string comes out\

on a single line"

运行结果:

The Capitol of New York is:  Albany

The Capitol of New York is:  $Z

 

Ben Franklin is on the $100.00 bill

Washington is not on the 100.00 bill

Lincoln is not on the $100.00 bill

Hamilton is not on the $a bill

Ben Franklin is on the $100.00 bill

 

................. examples of escape strings

Tab       Tab          Tab

This string prints out

on two lines

This string comes out on a single line

 

注意puts "Lincoln is not on the $$a bill"      ;# This is OK 体现了只置换一次的原则。

阅读(3211) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~