public static void main(String[] args) {
String str1="abcdefghij";
String str=(str1.subSequence(0,str1.length()-1)).toString(); //截取该字符串从开始位置到倒数第二个字符的位置,并转为字符串形式。
System.out.println(str);
}
如果你说的是 小数点前面的所有字符就是下面这段:
public static void main(String[] args) {
String str1="abc.def.ghi.j";
int num=0;
while((str1.indexOf(".", num))!=-1){
num=str1.indexOf(".",num)+1;
}
String str=(str1.subSequence(0,num-1)).toString();
System.out.println(str);
}
温馨提示:答案为网友推荐,仅供参考