Chinaunix首页 | 论坛 | 博客
  • 博客访问: 245540
  • 博文数量: 28
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 468
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-03 10:33
文章分类

全部博文(28)

文章存档

2011年(1)

2009年(14)

2008年(13)

我的朋友

分类:

2008-09-09 17:45:36

文件:

TCL中文教程.pdf

大小:

830KB

下载:

下载

 
TCL:字符串操作笔记
与字符串相关的命令:string、format、regexp、regsub、scan等
format命令
语法: format formatstring ?vlue value...?
scan命令
语法:scan string format varName ?varName...?
% scan "12.34.56.78" "%d.%d.%d.%d" c d e f
4
% puts [format "the value of c is %d, d is %d, e is %d, f is %d" $c $d $e $f]
the value of c is 12, d is 34, e is 56, f is 78
regexp命令:
语法:regexp ?switchs? ?--? exp string ?matchVar?\ ?subMatchVar subMatchVar...?
% regexp { ([0-9]+) *([a-z]+)} " there is 100 apples" total num word
1
% puts " $total ,$num,$word"
100 apples ,100,apples
 
switchs:
-nocase; -indices; -about; -expanded; -line; -linestop; -lineanchor; -all; -inline; -start index
--表示后面再也没有开关了,即使以“-”开头
regsub命令:
语法:regsub ?switchs? ?--? exp string subSpec varname
% regsub there "They live there lives " their x
1
% puts $x
They live their lives
switchs:
-nocase; -all; --
string命令:
语法:string option arg ?arg...?
1、string compare ?-nocase? ?-length int? string1 string2
2、string equal ?-nocase? ?-length int? string1 string2
3、string first string1 string2 ?startindex?
4、string last string1 string2 ?startindex?
5、string index string charIndex
6、string length string
7、string match ?-nocase? pattern string
% string match {a[b-f]cdef} accdef
1
8、string range string first last
9、string repeat string count
10、string replace string first last ?newstring?
11、string tolower string ?first? ?last?
12、string toupper string ?first? ?last?
13、string trim string ?chars?
14、string trimleft string ?chars?
15、string trimright string ?chars?
 
阅读(4005) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~