Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String URLEncode(String url) {

        url = url.replaceAll("%", "%25");
        url = url.replaceAll(" ", "%20");
        url = url.replaceAll("&", "%26");
        url = url.replaceAll("<", "%3c");
        url = url.replaceAll(">", "%3e");

        if (url.indexOf('^') >= 0) {
            url = url.replaceAll("^", "%22"); // 5e
        }

        url = url.replaceAll("'", "%27");
        url = url.replaceAll("\"", "%22");
        url = url.replaceAll(",", "%2c");
        url = url.replaceAll(":", "%3a");

        if ((url.indexOf('{') >= 0) || (url.indexOf('}') >= 0) || (url.indexOf('\\') >= 0)
                || (url.indexOf('|') >= 0) || url.indexOf('^') >= 0 || (url.indexOf('`') >= 0)) {
            url = null;
            return url;
        }
        return url;
    }
}