package test_fb_api;
import java.util.Arrays;
public class testStringSplite {
public static void main(String[] args) {
String locat = "http://ibobar-content.oss-cn-hangzhou.aliyuncs.com/book1669/hj1669_ipad.png";
String[] temp = locat.split("/");
String downloadPath = "ibobar" + "/" + "getBookList"
+ "/" + temp[temp.length - 2] + ".jpg";
System.out.println("method 1:");
String ss = temp[temp.length - 1];
String[] temp2 = ss.split("\\.");
System.out.println("副檔名 = "+temp2[temp2.length - 1]);
//System.out.println(Arrays.toString(temp2));
System.out.println("===============================");
System.out.println("method 2:");
int startIndex = ss.lastIndexOf(46) + 1;
int endIndex = ss.length();
System.out.println("副檔名 = " + ss.substring(startIndex, endIndex)); // 副檔名
}
}
廣告
2015年2月1日 星期日
[java] split string by dot | 用 dot 來切割字串
訂閱:
張貼留言 (Atom)

沒有留言:
張貼留言