private static String obterCaracterTratado(char caracter) { String retorno = null; int posicao = pstrCaracteresValidosEntrada.indexOf(caracter); if (posicao >= 0 && caracter != '/') { retorno = String.valueOf(caracter); } else { retorno = StringUtil.converterEntreBases(String.valueOf((int) caracter), 10, 16); if (retorno.length() == 1) { retorno = "/0" + retorno; } else { retorno = "/" + retorno; } } return retorno; }
private static String obterStringOriginal(String strStringTratada) { StringBuffer strNovaString = new StringBuffer(); String strCaracterOriginal; int intPosicao; intPosicao = strStringTratada.indexOf("/"); while (intPosicao >= 0) { strCaracterOriginal = strStringTratada.substring(intPosicao + 1, intPosicao + 3); // Tenta converter o código para o caracter original strCaracterOriginal = StringUtil.converterEntreBases(strCaracterOriginal, 16, 10); // Define as novas strings strNovaString.append(strStringTratada.substring(0, intPosicao)); strNovaString.append((char) Integer.parseInt(strCaracterOriginal)); strStringTratada = strStringTratada.substring(intPosicao + 3); intPosicao = strStringTratada.indexOf("/"); } return strNovaString.toString() + strStringTratada; }