java中能够运用substring()要领截取字符串前几位。
substring() 要领返回字符串的子字符串。
语法:
public String substring(int beginIndex)
或
public String substring(int beginIndex, int endIndex)
参数:
beginIndex -- 肇端索引(包含), 索引从 0 最先。
endIndex -- 完毕索引(不包含)。
返回值
子字符串。
示例:
public class Test { public static void main(String args[]) { String Str = new String("www.ki4.cn"); System.out.print("返回值 :" ); System.out.println(Str.substring(4) ); System.out.print("返回值 :" ); System.out.println(Str.substring(4, 10) ); } }
更多java学问请关注java基础教程。
以上就是java中怎样截取字符串前几位的细致内容,更多请关注ki4网别的相干文章!