截取url最后一个“/”后的字符

直接上代码了。

String url = "http://localhost:8080/mdoss/casdImg/gzpanyuschool.jpg";
String str= url.substring(url.lastIndexOf("/")+1);
lastIndexOf(String str)
该方法用于返回字符串最后一次出现的索引位置。当调用字符串的lastIndexOf()方法时,

会从当前字符串的开始位置检索参数字符串str,并将最后一次出现str的索引位置返回。

如果没有检索到字符串str,该方法返回-1.

如果lastIndexOf方法中的参数是空字符串"" ,则返回的结果与length方法的返回结果相同。
substring(int beginIndex)
该方法返回的是从指定的索引位置开始截取知道该字符串结尾的子串。
String str = "Hello word";
String substr = str.substring(3); //获取字符串,此时substr值为lo word

substring(int beginIndex, int endIndex)

beginIndex : 开始截取子字符串的索引位置

endIndex:子字符串在整个字符串中的结束位置
String str = "Hello word";
String substr = str.substring(0,3); //substr的值为hel
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值