JAVA中字符串函数subString的用法小结

来源:互联网 发布:mac粘贴文件 编辑:程序博客网 时间:2024/05/18 02:19

String str;
str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;

str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;

demo:

复制代码 代码如下:

class Test
{
 public static void main(String[] args)
 {
  String s1 ="1234567890abcdefgh";
  s1 = s1.substring(10);
  System.out.println(s1);
 }
}

运行结果:abcdefgh
复制代码 代码如下:

class Test
{
 public static void main(String[] args)
 {
  String s1 ="1234567890abcdefgh";
  s1 = s1.substring(0,9);
  System.out.println(s1);
 }
}

运行结果:123456789
0 0
原创粉丝点击