首页 > 其他 > 详细

String类之substring--->查找某位置对应的字

时间:2016-01-03 19:32:43      阅读:164      评论:0      收藏:0      [点我收藏+]

以下方法都是java内置类String类的内置方法(不是构造方法哦,就是普通的方法),不需要我们写,直接拿过来用即可。

 

substring方法对应Api介绍

技术分享

 

 

查找字符串中的 从int beginIndex及其以后的字符串:substring(int beginIndex)

public class Demo {
    public static void main(String[] args)  {
        String Str="MyNameIsDsh";
        String substr=Str.substring(8);//截取字符串Str第8位之后的字符
        System.out.println("截取后的新字符串是:"+substr);
    }
}

截取后的新字符串是:Dsh

 

 

查找字符串中的 从int beginIndex-int endIndex之间的字符串:substring(int beginIndex,int endIndex)

public class Demo {
    public static void main(String[] args)  {
        String Str="MyNameIsDsh";
        String substr=Str.substring(8,10);//截取字符串Str第8-10位之间的字符串
        System.out.println("截取后的新字符串是:"+substr);
    }
}

截取后的新字符串是:Ds

 

 

如果超出查找字符串本身长度核报异常:String index out of range

String类之substring--->查找某位置对应的字

原文:http://www.cnblogs.com/flyings/p/5096850.html

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