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

解决方案 »

  1.   

    String str = "111/123/123/123.mpc";
    System.out.println(str.substring(str.lastIndexOf("/")+1));
      

  2.   

    用lex處理這類問題是最為簡潔的
      

  3.   

    在网页源你码里面,首先找到 音/视频文件. 具体做法就是找到的后缀名, 比如 .mp3,.wma 等
    然后再找到这些文件前面最近的杠杠或者引号或等于号
    然后再截子串这样就找到了音/视频文的名称
      

  4.   

    在网页的源代码中,如何找歌曲名呢?那里面“/”很多啊,如何定位呢?
    --------
    lastIndexOf不可以吗,定位到最后一个
      

  5.   

    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 的值就是你要的咚咚。
      

  6.   

    这个也应该是java程序吧。Apache提供的oro,是个好东西,有兴趣的朋友可以研究研究。
      

  7.   

    你们帮我看看我的思路对不对:
    我也不知道代码写的对不对
    以下主要是找歌曲的名字
    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;
        }
      

  8.   

    以上我是想先找到比如.mp3然后记录位置endpos,然后从startpos开始到endpos最后一个出现的“/”的位置j,j到endpos中间的就是歌曲名,不知道这样行不?