append    Append values to variable

binary      Insert and extract fields from binary strings

regexp      Regular expression pattern matching

ex1:

regexp {^[0-9]+$}   510

->1

regexp {^[0-9]+$}  -510

-> 0

regexp  {^([0-9]+) *([a-z]+)} "Walk 10 km”  a b c

# a = 10km ; b = 10 ; c =km

-indices  返回索引值,a 为5 9 ,b 为5 6  ,c 为 7 9

-inline    返回数据列表   {10 km}  10 km

-line       激活分换行的匹配  $除普通功能外,与新行前的空字符串匹配。^除了它的普通功能外,与新行后的空字符串匹配

regsub      Regular expression string substution

regsub there "they live there lives"   their x

->1    #返回1 匹配成功,x = they live their lives

regsub  thrre "they live there lives" their x

->0 #返回0 匹配不成功 ,x= they live there lives.无论是否发生替换,都会设置x 变量

-all 一直查找替换,否则只替换1次。返回替换次数

regsub zz abbab  a  x  # x=zzbbab

regsub -all zz abbab a x  # x=zzbbzzb  返回值为2

-nocase 不区分大小写

-start  从指定字符处开始查找。命令指定字符中一个字符索引

-line 启动区分换行匹配

--明确的表示命令选项结束

regsub  -all --  a|b  axaab  &&  x  #x=aaxaaaabb   &表示被替换的子字符串

regsub -all  -- (a+)(ba*)  aabaabxab  {z\2}  x     #  x=zbaabxzb 后面有一个b,前面没有1个b的序列替换为z

format      printf() -style string formatting

ex1:

set msg  [format  "%s is %d years old]

set msg  "$name is $age years old"

ex2:

puts [format "%4d %12.3f"  $i  [expr exp($i)]]

scan          sscanf() -style string formatting

ex1:

scan "16 units,24.2% margin"  "%d units, %f margin"  a b      #a的值为16,b的值为24.2

->2           #完成两次转换

ex2:

proc next c {

scna $c %c   i  # ASCII 转为整数

format %c [expr {$i + 1}]   #整数加一转为 ASCII

}

next a

-> b

string compare   Lexical(词汇的) string comparison

string first     Search for first occurrence of substring

string index     Return character from string

string last        Search for last occurance of substring

string length    Return number of characters in string

string range     Return range of characters in string

string tolower   Covert to lowercase

string toupper   Covert to uppercase

string trim          Remove leading and trailing characters

string trimleft      Remove leading characters

string trimright   Remove trailing characters

string wordend   Return end position of word in string

string wordstart  Return start position of word in string

subst                  Blackslash,command,variable substitutions

string map  dictionary string  # string中出现dictionary关键字置换为相应的值  -nocase  不区分大小写

string  is  digital  1234  #数据类型判断,ascii/boolean/double/float/integer/list/lower/alpha

->1

Tcl 有两种匹配模式:

1.简单的通配符样式,源于unix外壳中的文件名展开机制

*   0个或多个任意字符组成的字符匹配

? 一个任意字符匹配

[chars]   chars中任意一个字符匹配

\x   于单字符x匹配,用于特殊字符,如* ? [ ] \

2.正则表达式模式匹配

.  匹配任意的单个字符

^ 指定与输入字符串的开头匹配

$指定与输入字符串的结尾匹配

\m 指定单词的开头进行匹配

\M 指定单词的结尾进行匹配

\k 匹配非字母也非数字的字符k(\.匹配字面上的句点符号)

[chars]  与chars 中的字母匹配

(regexp) 匹配正则表达式 regexp 用于分组或识别匹配的子字符串

*  与0或多个前述的原子组成的序列匹配

+ 与1个或多个前述的原子组成的序列匹配

?与空字符串匹配,或与前述的一个原子匹配

{m}   与前述原子正好匹配m次的序列

{m,}  与前述原子至少匹配m次的序列

{m,n}  至少匹配m次,最多n次

re1 | re2  任意一个指定正则表达式的匹配

转义序列

\a   铃声

\b 退格

\B 反斜线,与\ 相同

\cX  取得给定字符X的低5位,然后以这5位为低5位,其他补0做转义后的字符

\e 转义字符

\f 换页

\n 换行

\r 回车

\t 制表符

分支和量词

* + ? 被称为量词,可以跟在原子后面,用来指定它的重复次数。

* 0或多个该原子组成的匹配序列

+ 1个或多个该原子组成的匹配序列

? 空字符串或与这个字符串匹配字符串匹配

{num} 0-255 之间的整数

逆向引用

([ab])\1       #匹配aa bb

非捕获子表达式:处理速度快,不能逆向引用非捕获子表达式。

(?:expression)

TCL Strings的更多相关文章

  1. Tcl之group arguments

    1 doubel quotes This allows substitutions to occur within the quotations - or "interpolation&qu ...

  2. Tcl之Math

    expr is for Tcl to do math operations. It takes all of its arguments ("2 + 2" for example) ...

  3. Hacker Rank: Two Strings - thinking in C# 15+ ways

    March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...

  4. Tcl internal variables

    Tcl internal variables eryar@163.com 在Tcl中内置了一些变量,并赋予了一定的功能.内置变量列表如下: 变量名称 功能描述 argc 指命令行参数的个数. argv ...

  5. StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?

    StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...

  6. Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  7. [LeetCode] Add Strings 字符串相加

    Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...

  8. [LeetCode] Encode and Decode Strings 加码解码字符串

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  9. [LeetCode] Group Shifted Strings 群组偏移字符串

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

随机推荐

  1. layui树形结构更改

    /* * 将json字符串更改为layui.tree所用的数据结构类型,输出仍然为json字符串 * tanghao 7.29 */ function dataToTreeData(oData_str ...

  2. 并查集-E - Wireless Network

    E - Wireless Network An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...

  3. SpringMVC 源代码深度解析 IOC容器(Bean 解析、注册)

    SpringMVC通过一个配置文件描述Bean以及Bean之间的依赖关系,利用Java的反射机制实例化Bean并建立Bean之间的依赖关系.IOC容器在完成这些底层工作的基础还提供了Bean的实例缓. ...

  4. Centos7更改网卡名称Eth0

    标签: Centos7更改网卡名称 2016-12-06 21:55 8737人阅读 评论(1) 收藏 举报  分类: linux(6)  作者同类文章X 版权声明:本文为博主原创文章,未经博主允许不 ...

  5. CSS技巧!鼠标经过图片抖动效果

    把代码加到style.css(模板的主css里面): /**图片抖动**/ img:hover{-webkit-animation: tada 1s .2s ease both;-moz-animat ...

  6. xstart访问centos7

    参考文档:https://blog.csdn.net/wuzhimang/article/details/51523867

  7. 【牛客小白月赛21】NC201604 Audio

    [牛客小白月赛21]NC201604 Audio 题目链接 题目大意: 给出三点 ,求到三点距离相等的点 的坐标. 解析 考点:计算几何基础. 初中蒟蒻表示不会什么法向量.高斯消元..qwq 方法一: ...

  8. 剑指offer 面试题. 数据流中的中位数

    题目描述 如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值.如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值.我们 ...

  9. 使用LxRunOffline工具备份/还原Linux子系统(WSL)

    安装WSL 开启WSL组件 首先需要打开WSL组件,可以使用以下命令: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Win ...

  10. Linux线程间同步的几种方式

    信号量 信号量强调的是线程(或进程)间的同步:"信号量用在多线程多任务同步的,一个线程完成了某一个动作就通过信号量告诉别的线程,别的线程再进行某些动作(大家都在sem_wait的时候,就阻塞 ...