Java String Escape escapeSelected(String str, String chars)

Here you can find the source of escapeSelected(String str, String chars)

Description

escape Selected

License

Open Source License

Declaration

public static String escapeSelected(String str, String chars) 

Method Source Code


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

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

public class Main {
    public static String escapeSelected(String str, String chars) {
        chars = "%" + chars;
        for (int i = 0; i < chars.length(); i++) {
            String charAsStr = chars.substring(i, i + 1);
            try {
                str = str.replace(charAsStr, URLEncoder.encode(charAsStr, "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("UTF-8 encoding not found:", e);
            }//from  w w  w  .j  a va  2 s. com
        }
        return str;
    }
}

Related

  1. escapeRegex(String regex)
  2. escapeRegexChars(String str, char... ignores)
  3. escapeRegexp(final String str)
  4. escapeRegexpSymbol(String expr)
  5. escapeReservedWord(String input)
  6. escapeSolr(String value)
  7. escapeToFileName(String name)
  8. escapeUnicode(String s)
  9. escapeUnicodeString(final String input, final boolean escapeAscii)