Java URL Encode urlEncodeForSpaces(String input)

Here you can find the source of urlEncodeForSpaces(String input)

Description

This method encodes the url, removes the spaces from the url and replaces the same with "%20".

License

Open Source License

Parameter

Parameter Description
input the input string

Return

the string

Declaration

public static String urlEncodeForSpaces(String input) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w ww  .j  a va 2 s  .c  o m
     * This method encodes the url, removes the spaces from the url and replaces
     * the same with <code>"%20"</code>.
     *
     * @param input the input char array
     * @return the string
     */
    public static String urlEncodeForSpaces(char[] input) {
        StringBuffer retu = new StringBuffer(input.length);
        for (int i = 0; i < input.length; i++) {
            if (input[i] == ' ') {
                retu.append("%20");
            } else {
                retu.append(input[i]);
            }
        }
        return retu.toString();
    }

    /**
     * This method encodes the url, removes the spaces from the url and replaces
     * the same with <code>"%20"</code>.
     *
     * @param input the input string
     * @return the string
     */
    public static String urlEncodeForSpaces(String input) {
        return urlEncodeForSpaces(input.toCharArray());
    }
}

Related

  1. urlEncode(String urlPlain)
  2. urlEncodeFilename(char[] input)
  3. URLEncodeFilePath(String s)
  4. urlEncodeForSpaces(String href)
  5. urlEncodeForSpaces(String input)
  6. urlEncodeParameter(String value)
  7. URLEncoder(String str)
  8. urlEncodeSpace(String s)
  9. urlParameterEncode(String s)