Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static String getParameterFromUrl(String url, String param) {
        //Log.d(TAG, "getParameterFromUrl:"+url+"-p:"+param);
        URL iurl;
        try {
            iurl = new URL(url);
            String iquery = iurl.getQuery();
            if (iquery == null) {
                return "";
            } else {
                String[] q = iquery.split("&");
                for (int i = 0; i < q.length; i++) {
                    String[] xx = q[i].split("=");
                    if (xx[0].equals(param) && xx.length > 1) {
                        return xx[1];
                    }
                }
                return "";
            }

        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }
    }
}