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 的值就是你要的咚咚。
这个也应该是java程序吧。Apache提供的oro,是个好东西,有兴趣的朋友可以研究研究。
你们帮我看看我的思路对不对: 我也不知道代码写的对不对 以下主要是找歌曲的名字 class StringSub { public StringSub() { song = new ArrayList<String>();//存放歌的名字 format = new ArrayList<String>();//存放格式 } private ArrayList<String> song; public ArrayList<String> format; public int subword(String a, ArrayList<String> b) { int arrayofnum = 0;//记录歌曲名的个数 int startpos = 0;//开始位置 int endpos = 0;//结束位置 int i = 0;//格式ArrayList<String>();下标 if (b.isEmpty()) return -1; while (i < b.size()) { endpos = a.indexOf(b.get(i), startpos); while (endpos != -1) { int j; j = a.substring(startpos, endpos - startpos).lastIndexOf("/"); song.add(a.substring(j, endpos)); startpos = endpos + 1; arrayofnum++;
System.out.println(str.substring(str.lastIndexOf("/")+1));
然后再找到这些文件前面最近的杠杠或者引号或等于号
然后再截子串这样就找到了音/视频文的名称
--------
lastIndexOf不可以吗,定位到最后一个
把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 的值就是你要的咚咚。
我也不知道代码写的对不对
以下主要是找歌曲的名字
class StringSub {
public StringSub()
{
song = new ArrayList<String>();//存放歌的名字
format = new ArrayList<String>();//存放格式
} private ArrayList<String> song;
public ArrayList<String> format;
public int subword(String a, ArrayList<String> b) {
int arrayofnum = 0;//记录歌曲名的个数
int startpos = 0;//开始位置
int endpos = 0;//结束位置
int i = 0;//格式ArrayList<String>();下标
if (b.isEmpty())
return -1;
while (i < b.size()) {
endpos = a.indexOf(b.get(i), startpos);
while (endpos != -1) {
int j;
j = a.substring(startpos, endpos - startpos).lastIndexOf("/");
song.add(a.substring(j, endpos));
startpos = endpos + 1;
arrayofnum++;
}
}
return arrayofnum;
}