首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

如何样截取网址中的歌曲名

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

怎么样截取网址中的歌曲名?
请问比如字符串: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 的值就是你要的咚咚。

热点排行