java如何剪切字符串的最后几个字符:
要在java中剪切字符串的最后几个字符,请使用String类的substring方法。 关于具体的使用方法,请参照以下说明。
1、substring(intbeginindex ) substring(intbeginindex ) )。
returnsanewstringthatisasubstringofthisstring .剪切
剪切字符串位置beginIndex-1及更高版本的所有字符。 请注意,字符的开始位置从0开始。
示例: string name=' Wei cc-2010 01 07-00001 ';
system.out.println (name.substring ) name.length((-5 ); //输出00001
2、substring(intbeginindex,int endIndex ) substring(intbeginindex,int endIndex ) )。
returnsanewstringthatisasubstringofthisstring。
剪切从字符串位置beginIndex到位置endIndex-1的所有字符。 此方法将在前面关闭和打开包含beginIndex位置字符但不包含endIndex位置字符的字符。
示例: string name=' Wei cc-2010 01 07-00001 ';
system.out.println (name.substring (name.length ) (-5,name.length ) ); //输出00001
更多的java知识请关注java基础教程栏。