substring(x)和substring(x,y)的用法

substring(x)和substring(x,y)的用法

代码:

public class textmu {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
    String id="123454321";
    String shortId,longId,Id;
    shortId=id.substring(2,7);
    longId=id.substring(1,8);
    Id=id.substring(4);
    System.out.println(shortId);
    System.out.println(longId);
    System.out.println(Id);
 }

}




总结:substring(x)是从字符串的的第x个字符截取

          substring(x,y)是从x到y前的位置停止

答案:


---------------------
作者:yhs17865569668
来源:CSDN
原文:https://blog.csdn.net/yhs17865569668/article/details/78189525/
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/xiaoshen666/p/10824099.html