substring的用法
str=str.substring(int beginIndex); 截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;
str=str.substring(int beginIndex,int endIndex); 截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;
-
beginIndex -- 起始索引(包括), 索引从 0 开始。
-
endIndex -- 结束索引(不包括)。
演示程序:
public class Test {
public static void main(String[] args) {
String Str = new String("www.sina.com");
System.out.print("返回值 :" );
System.out.println(Str.substring(4));
System.out.print("返回值 :" );
System.out.println(Str.substring(4, 10));
}
}