get Value From Query String by key - Android java.net

Android examples for java.net:URL

Description

get Value From Query String by key

Demo Code

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.security.SecureRandom;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class Main{

    public static String getValueFromQueryString(String url, String key) {
        int keyStPos = url.indexOf(key + "=") + key.length() + 1;
        if (keyStPos == -1) {
            return "";
        }// w w w.jav  a 2  s. c  om
        int keyEnPos = url.indexOf("&", keyStPos);
        if (keyEnPos == -1) {
            keyEnPos = url.length();
        }
        return url.substring(keyStPos, keyEnPos);
    }

}

Related Tutorials