Java tutorial
//package com.java2s; import android.text.TextUtils; public class Main { private static final int[] PIC_WIDTH = { 30, 60, 80, 120, 160, 200, 300, 400, 600, 800 }; public static String getPicUrl(String baseProImgUrl, int size, int index) { if (TextUtils.isEmpty(baseProImgUrl)) return ""; int end = baseProImgUrl.lastIndexOf("?"); String str_timemark = ""; if (end > 0) { str_timemark = baseProImgUrl.substring(end); // /?123445 } end = baseProImgUrl.lastIndexOf("/"); String innerUrl = baseProImgUrl.substring(0, end); end = innerUrl.lastIndexOf("/"); String head = innerUrl.substring(0, end); String mid = innerUrl.substring(end); String items[] = mid.split("\\."); if (null == items || items.length != 3) return ""; int flag = 0; for (int len = PIC_WIDTH.length, i = len - 1; i > -1; i--) { if (size >= PIC_WIDTH[i]) { flag = i; break; } } if (flag >= PIC_WIDTH.length) flag = PIC_WIDTH.length - 1; int resolution = PIC_WIDTH[flag] == 800 ? 0 : PIC_WIDTH[flag]; String result = head + items[0] + "." + index + "." + items[2] + "/" + resolution + str_timemark; return result; } }