Java String Encode encodeValue(String dirtyValue)

Here you can find the source of encodeValue(String dirtyValue)

Description

Helper function for character encoding

License

Open Source License

Parameter

Parameter Description
dirtyValue a parameter

Return

encoded value

Declaration

public static String encodeValue(String dirtyValue) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main {
    /**/*w ww .  j a  va 2 s  .  c  om*/
     * Helper function for character encoding
     *
     * @param dirtyValue
     * @return encoded value
     */
    public static String encodeValue(String dirtyValue) {
        String cleanValue = "";

        try {
            cleanValue = URLEncoder.encode(dirtyValue, "UTF-8").replace("+", "%20");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return cleanValue;
    }
}

Related

  1. encodeToString(String s)
  2. encodeURNComponent(String value)
  3. encodeUTF8(String input, boolean keepSpaces)
  4. encodeUTF8(String s)
  5. encodeUTF8(String s)
  6. encodeValue(String str)
  7. encodeValue(String value)