日期:2014-05-20  浏览次数:20672 次

怎么样截取网址中的歌曲名?
请问比如字符串:www.202.162.125.10/……/连哭都是我的错.mp3,怎么样提取歌曲名?

------解决方案--------------------
String str = "111/123/123/123.mpc ";
System.out.println(str.substring(str.lastIndexOf( "/ ")+1));
------解决方案--------------------
http://jakarta.apache.org/site/downloads/downloads_oro.cgi
把2.0.8.zip down下来,加入到lib中

然后写代码:

public static void main(String[] args) throws MalformedPatternException {


String str = "www.202.162.125.10/……/xxxxxxxxxxxx.mp3 ";
String tag = ".+/(.+).mp3 ";

PatternCompiler compiler = new Perl5Compiler();
org.apache.oro.text.regex.Pattern patternTag = compiler.compile(tag,
Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher = new Perl5Matcher();
if (matcher.contains(str, patternTag)) {
MatchResult result = matcher.getMatch();
String name = result.group(1);
}
}

name 的值就是你要的咚咚。