Java String Sanitize sanitizeForSearch(String str)

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

Description

Sanitize the string for searching.

License

Open Source License

Declaration

public static String sanitizeForSearch(String str) 

Method Source Code

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

public class Main {
    /**//w  w w.ja  va 2  s .  c  om
     * Sanitize the string for searching.
     */
    public static String sanitizeForSearch(String str) {
        if (str == null) {
            return null;
        }
        return str
                //general case for punctuation
                .replace("`", " ").replace("!", " ").replace("#", " ")
                .replace("$", " ").replace("%", " ").replace("^", " ")
                .replace("&", " ").replace("[", " ").replace("]", " ")
                .replace("{", " ").replace("}", " ").replace("|", " ")
                .replace(";", " ").replace("*", " ").replace(".", " ")
                .replace("?", " ").replace("'", " ").replace("/", " ")
                //to prevent injection
                .replace("=", " ").replace(":", " ").replace("<", "&lt;")
                .replace(">", "&gt;");
    }
}

Related

  1. sanitizeFolderName(String s)
  2. sanitizeForCmisName(String in)
  3. sanitizeForCsv(String str)
  4. sanitizeForJson(String data)
  5. sanitizeForLogMessage(String unsanitizedString)
  6. sanitizeForSemgrexName(String text)
  7. sanitizeForTableName(String input)
  8. sanitizeForUri(String uri, String replace)
  9. sanitizeFullPrefixKey(String propKey)