Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1437930
  • 博文数量: 244
  • 博客积分: 3353
  • 博客等级: 中校
  • 技术积分: 3270
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-09 17:56
文章分类

全部博文(244)

文章存档

2023年(7)

2022年(7)

2021年(4)

2020年(1)

2019年(2)

2017年(2)

2016年(3)

2015年(11)

2014年(20)

2013年(10)

2012年(176)

分类: Python/Ruby

2012-06-24 15:11:32

package require Tcl
package require Tk
set str "This is a string"
puts "The string is :$str"
puts "The length of the string is [string length $str]"
puts "The character at index 3 is:[string index $str 3]"
puts "The character from index 4 through 8 are:[string range $str 4 8]"
puts "The index of the first occurrence of letter \"i\" is :[string first i $str]"
 
 
输出
The string is :This is a string
The length of the string is 16
The character at index 3 is:s
The character from index 4 through 8 are: is a
The index of the first occurrence of letter "i" is :2
 
结果分析[string index $str3]可以用来显示字符串中第四个字符为何(第一个字母的index为0),[string range $str 4 8]用以显示字符串的第五个到第九个字符,[string first i $str]用来显示字母i在字符串中第一次出现时的index值。
阅读(1654) | 评论(0) | 转发(0) |
0

上一篇:foreach学习(06)

下一篇:break和continue学习

给主人留下些什么吧!~~