ominous2012的个人空间 https://blog.eetop.cn/934213 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

tcl字符操作

已有 977 次阅读| 2016-1-17 20:12 |个人分类:tcl

1.string index  string idx
idx为0对应字符串的开头,1对应第二个,end对应字符串的结尾,end-1对应倒数第二个
2.string range string start  end
返回从start指向的位置到第二个索引之间的所有字符
% string index "sample string" 3
p
% string index "sample string" end
g
% string index "sample string" end-1      
n
% string range "Sample string" 3 7
ple s
% string range "sample string" 3 end
ple string
3.string length 返回字符串中字符的个数
string toupper 将字符串中所有的小写字母转换成大写字母
string tolower 将所有大写字母转换成小写字母
string trim把开头和结尾出现的要裁剪的字符都删去
string trimright  /string trimleft从字符串的结尾或者开头进行裁剪
% string length "Sample string"
13
% string toupper "watch out"
WATCH OUT
% string tolower "HELLo World"
hello world
% string trim aaxxxxbab abc
xxxx
% string trimleft  ghygh gy
hygh
% string trimright ghyghy ghy
% string trimright ghykj jk
ghy

4.string repeat  将字符串重复指定的次数
% string repeat "*" 20
********************
% string repeat abc 5
abcabcabcabcabc
5.string first 在第二个字符串中搜索与第一个字符串相同的子字符,如果找到,返回最左边的系统字符串的开头字符串的索引值,找不到返回-1
string last 返回的是最右边的系统子字符串的开头字符的缩影值
% string first th "There is the "
9
% string last the "the the the"
8

6.字符串比较
string compare  读入两个字符串进行比较,如果相同返回0,如果第一个字符串先与第二个字符串,返回-1;如果第一个后于第二个,返回1
% string compare mic mia
1
% string compare mia mic
-1
% string compare mia mia
0

string equal如果他们严格相同,就返回1,否则返回0.除非指定-nocase.还可以设置-length选项,指定对当前length个字符进行比较。
% string equal cs cs
1
% string equal dog Dog
0
% string equal dog Dog -nocase 
bad option "dog": must be -nocase or -length
% string equal -nocase dog Dog
1
% string equal -length cagt cat
wrong # args: should be "string equal ?-nocase? ?-length int? string1 string2"
% string equal -length 2 cat carry
1



点赞

全部作者的其他最新日志

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 0

    好友
  • 0

    获赞
  • 1

    评论
  • 529

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-21 20:43 , Processed in 0.016173 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部