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);
//int beg = pic.indexOf("/",end);
String temp = str.substring(0,str.lastIndexOf("/")-1);
String result = temp.substring(temp.lastIndexOf("/"));
//int end = pic.lastIndexOf("/");
pic=pic.substring(0,end);
end = pic.lastIndexOf("/");
pic=pic.substring(end+1);
我简单的写了一下,可能没对,我只提供一种思路....
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());
}
}
}