首页 > 系统服务 > 详细

shell字符串索引

时间:2017-02-01 20:42:53      阅读:275      评论:0      收藏:0      [点我收藏+]

shell中的字符串索引一会从0开始,一会从1开始,见例子:

#!/bin/bash

string="hello world"
length=${#string}
echo "string is \""$string"\""
echo "length is $length"

index=`expr index "$string" o`
echo "index of ‘o‘ is $index"

substring=${string:$index}
echo "substring begins from index $index is \""$substring"\""
echo "shit happens"
echo

exit 0

输出如下:

技术分享

shell字符串索引

原文:http://www.cnblogs.com/gattaca/p/6360278.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!