日期:2014-05-20 浏览次数:20857 次
String s1 = "http://zhangmenshiting2.baidu.com/data2/music/5979788/5979788.mp3?xcode=047d3465cd5224a3ab9483faf71dddbb&mid=0.90150176693482"; String s2 = ""; s2 = s1.substring(s1.lastIndexOf("/") + 1, s1.lastIndexOf("?")); System.out.println(s2);
------解决方案--------------------
1.求出".mp3"在字符串中的下标end
2.获取最后".mp3"前最后一个“/”下标start
3.截取
string.substring(start + 1 ,end);
得到5979788
string.substring(start + 1 ,end + “.mp3”.length());
得到5979788.mp3
------解决方案--------------------