str = " http://item.slide.com/r/1/196/i/XEh4xdFF1T-i5OMWeIaezxPV0Yrlux-A/ ";我要取出最后 2个/ 之间的字符串,也就是 XEh4xdFF1T-i5OMWeIaezxPV0Yrlux-A//int end = pic.lastIndexOf("/");
//int beg = pic.indexOf("/",end);

解决方案 »

  1.   


    String temp = str.substring(0,str.lastIndexOf("/")-1);
    String result = temp.substring(temp.lastIndexOf("/"));
      

  2.   

    完全可以这么做,呵呵,不过你的第二个用错啦,可以取消最后一个/后面的字符串包括/也去掉,然后再找最后一个/,然后再取出字符串来。
    //int end = pic.lastIndexOf("/"); 
    pic=pic.substring(0,end);
    end = pic.lastIndexOf("/"); 
    pic=pic.substring(end+1);
      

  3.   

    你可以用String 类的split方法自己试试
      

  4.   

    System.out.println(str.substring(str.lastIndexOf("/",str.lastIndexOf("/")-1)+1, str.lastIndexOf("/")));咩
      

  5.   

    建议用正则表达式去解决.
    我简单的写了一下,可能没对,我只提供一种思路....
    import java.util.HashMap;
    import java.util.Map;public class Testchar {
    public static void main(String[] args) {
    String str = " http://item.slide.com/r/1/196/i/XEh4xdFF1T-i5OMWeIaezxPV0Yrlux-A/ ";
    java.util.regex.Pattern p = java.util.regex.Pattern.compile("/[^:;]*/");
    java.util.regex.Matcher m = p.matcher(str);
    while (m.find()) {
    System.out.println(m.group());
    }
    }
    }