Here you can find the source of percentEncode(String s)
Parameter | Description |
---|---|
s | a string to encode |
public static String percentEncode(String s)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static final String ENCODING = "UTF-8"; /**// w w w . j a v a 2 s.c o m * Percent encode a string * @param s a string to encode * @return an encoded string */ public static String percentEncode(String s) { String result = ""; try { if (s != null) { result = URLEncoder.encode(s, ENCODING).replace("%7E", "~") .replace("*", "%2A").replace("+", "%20"); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } return result; } }