Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package br.com.pfood.util; import java.io.UnsupportedEncodingException; import org.apache.commons.codec.digest.DigestUtils; public class StringUtils { public static String tratarCaracterEspecial(String str) { str = str.replaceAll("[?A]", "A"); str = str.replaceAll("[]", "a"); str = str.replaceAll("[E]", "E"); str = str.replaceAll("[]", "e"); str = str.replaceAll("[??I]", "I"); str = str.replaceAll("[]", "i"); str = str.replaceAll("[O]", "O"); str = str.replaceAll("[]", "o"); str = str.replaceAll("[U]", "U"); str = str.replaceAll("[]", "u"); str = str.replaceAll("[C]", "C"); str = str.replaceAll("", "c"); str = str.replaceAll("[]", "y"); str = str.replaceAll("?", "Y"); str = str.replaceAll("", "n"); str = str.replaceAll("", "n"); str = str.replaceAll("!", ""); str = str.replaceAll("&", ""); str = str.replaceAll("\\$", ""); str = str.replaceAll("\\", ""); str = str.replaceAll("\\", ""); str = str.replaceAll("\\?", ""); str = str.replaceAll("\\)", "_"); str = str.replaceAll("\\(", "_"); str = str.replaceAll("\\|", "_"); str = str.replaceAll("\\", "_"); str = str.replaceAll("\\", "_"); str = str.replaceAll("\\", "_"); return str; } public static String tratarCaracterEespacaoBranco(String text) { String stg = text; while (stg.contains(" ")) { stg = stg.replaceAll(" ", "_"); } stg = stg.replaceAll("[?A]", "A"); stg = stg.replaceAll("[]", "a"); stg = stg.replaceAll("[E]", "E"); stg = stg.replaceAll("[]", "e"); stg = stg.replaceAll("[??I]", "I"); stg = stg.replaceAll("[]", "i"); stg = stg.replaceAll("[O]", "O"); stg = stg.replaceAll("[]", "o"); stg = stg.replaceAll("[U]", "U"); stg = stg.replaceAll("[]", "u"); stg = stg.replaceAll("[C]", "C"); stg = stg.replaceAll("", "c"); stg = stg.replaceAll("[]", "y"); stg = stg.replaceAll("?", "Y"); stg = stg.replaceAll("", "n"); stg = stg.replaceAll("", "n"); stg = stg.replaceAll("!", ""); stg = stg.replaceAll("&", ""); stg = stg.replaceAll("\\$", ""); stg = stg.replaceAll("\\", ""); stg = stg.replaceAll("\\", ""); stg = stg.replaceAll("\\?", ""); stg = stg.replaceAll("-", "_"); stg = stg.replaceAll("\\)", "_"); stg = stg.replaceAll("\\(", "_"); stg = stg.replaceAll("\\|", "_"); stg = stg.replaceAll("\\", "_"); stg = stg.replaceAll("\\", "_"); stg = stg.replaceAll("\\", "_"); return stg; } /* public static String trataCaracterCNPJCPF(String cpfCnpj){ cpfCnpj = cpfCnpj.replace(Pattern.quote("\\") , ""); cpfCnpj = cpfCnpj.replace(Pattern.quote("/") , ""); cpfCnpj = cpfCnpj.replace(Pattern.quote(".") , ""); cpfCnpj = cpfCnpj.replace(Pattern.quote(",") , ""); cpfCnpj = cpfCnpj.replace(Pattern.quote("-") , ""); cpfCnpj = cpfCnpj.replace(Pattern.quote("_") , ""); cpfCnpj = cpfCnpj.replace(Pattern.quote(" ") , ""); return cpfCnpj; } */ public static String removeHTML(String htmlString) { // Remove HTML tag from java String String noHTMLString = htmlString.replaceAll("\\<.*?\\>", ""); // Remove Carriage return from java String noHTMLString = noHTMLString.replaceAll("\r", ""); // QUEBRA DE LINHA // Remove New line from java string and replace html break noHTMLString = noHTMLString.replaceAll("\n", " "); noHTMLString = noHTMLString.replaceAll("\'", "'"); noHTMLString = noHTMLString.replaceAll("\"", """); return noHTMLString; } public static String getMD5(String senha) { String md5 = ""; try { md5 = DigestUtils.md5Hex(senha.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return md5; } public static String removeCaracterEspecial(String content) { content = content.replaceAll("(\\r|\\n|\\t)", ""); return content; } public static String removeEspacosEmBranco(String content) { if (content != null) { content = content.replaceAll("(\\s)", ""); } return content; } public static String removeQuebraDeLinha(String content) { if (content != null) { content = content.replaceAll("(\\n|\\r)", "").trim(); } return content; } public static String limpaCpfCnpj(String pCpfCnpj) { String cpfCnpj = null; if (pCpfCnpj != null) { cpfCnpj = pCpfCnpj.replaceAll("[^0-9A-Za-z]", ""); } return cpfCnpj; } }