示例函数
/**
* 处理URL请求链接参数绑定
* @param paramStr
* @param params
* @return
*/
public static String getUrlFromXml(String paramStr,
Object... params) {
String string = paramStr;
if(string == null) return "";
String reg = "\\{.+?\\}";
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(string);
int index = 0;
while (m.find() && index < params.length) {
string = string.replaceFirst(reg, params[index]==null?"":params[index].toString());
index++;
}
return string;
}
调用方式
String url = "/aaa/aaa/aaa/aaa/aa/{a}/{b}/{c}/{d}";
String resultStr = HttpUtil.getUrlFromXml(url,"1","2","3","4");
Log.d("Carson",resultStr);
示例
网友评论