java如何获取最后一个点前面的字符串
时间: 2024-01-28 16:03:56 浏览: 25
可以使用String类的lastIndexOf方法来获取最后一个点的位置,然后再使用substring方法获取最后一个点前面的字符串。
示例代码:
```
String str = "abc.def.ghi";
int lastDotIndex = str.lastIndexOf(".");
String result = str.substring(0, lastDotIndex);
System.out.println(result); // 输出: abc.def
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)