从url中提取参数:

public static String getUrlparameter(String url, String name) {
        url += "&";
        String pattern = "(\\?|&){1}#{0,1}" + name + "=[a-zA-Z0-9]*(&{1})";
        Pattern r = Pattern.compile(pattern);
        Matcher matcher = r.matcher(url);
        if (matcher.find()) {
            return matcher.group(0).split("=")[1].replace("&", "");
        } else {
            return null;
        }
    }

使用方法:

Log.d(TAG," a === >>" + StringUtils.getUrl(result,"a"));
Log.d(TAG," p === >>" + StringUtils.getUrl(result,"p"));
Log.d(TAG," c === >>" + StringUtils.getUrl(result,"c"));
posted on 2022-07-26 13:47  广坤山货  阅读(3833)  评论(0编辑  收藏  举报