
java截取字符串后几位字符的要领:
java中截取字符串中最后几个字符能够运用String类的substring要领,细致用法参考下方申明:
1、substring(int beginIndex)
substring(int beginIndex)
Returns a new string that is a substring of this string.截取
截取字符串位置beginIndex-1及今后的一切字符,注重字符的肇端位置是从0入手下手的。
例:
String name="weicc-20100107-00001"; System.out.println(name.substring(name.length()-5));//输出00001
2、substring(int beginIndex, int endIndex)
substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string.
截取字符串位置beginIndex到位置endIndex-1的一切字符,此要领前闭后开的,即包含beginIndex位置的字符然则不包含endIndex位置的字符。
例:
String name="weicc-20100107-00001"; System.out.println(name.substring(name.length()-5,name.length()));//输出00001
更多java学问请关注java基础教程栏目。
以上就是java截取字符串后几位字符的要领的细致内容,更多请关注ki4网别的相干文章!