java 字符串如果有.xxx后缀截取去掉
时间: 2023-07-01 10:25:24 浏览: 175
可以使用 String 类的 substring() 方法来截取字符串,然后使用 String 类的 replace() 方法来去掉 .xxx 后缀。具体操作如下:
假设字符串为 str,.xxx 后缀的长度为 n,则可以这样做:
```
String newStr = str.substring(0, str.length() - (n + 1)).replace(".", "");
```
其中,substring() 方法的参数是要截取的子字符串的起始索引和终止索引,replace() 方法的参数是要被替换的字符串和替换后的字符串。这样就可以得到去掉 .xxx 后缀的新字符串 newStr。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)