Java URL Encode urlEncode(String str)

Here you can find the source of urlEncode(String str)

Description

url Encode

License

Apache License

Declaration

public static String urlEncode(String str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String urlEncode(String str) {
        if (str == null)
            return null;

        StringBuffer tmp = new StringBuffer();

        for (int i = 0; i < str.length(); ++i) {
            char a = str.charAt(i);
            if (((a < ':') && (a > '/')) || ((a < '[') && (a > '@')) || ((a < '{') && (a > '`')) || (a == '_'))
                tmp.append(a);//from   ww w  .  j  av a 2  s  . co m
            else if (a < '\16')
                tmp.append("%0" + Integer.toHexString(a));
            else
                tmp.append("%" + Integer.toHexString(a));
        }

        return tmp.toString();
    }
}

Related

  1. urlencode(byte[] unencodedBytes)
  2. URLEncode(String in)
  3. urlEncode(String origString)
  4. URLencode(String s)
  5. urlEncode(String str)
  6. urlEncode(String str)
  7. urlEncode(String urlPlain)
  8. urlEncodeFilename(char[] input)
  9. URLEncodeFilePath(String s)