Java特殊字符转义(、"、/、&)

public static String filter(String value)
    {
        if(value == null){
            return null;
        }else{
        char content[] = new char[value.length()];
        value.getChars(0, value.length(), content, 0);
        StringBuffer result = new StringBuffer(content.length + 50);
        for(int i = 0; i < content.length; i++)
            switch(content[i])
            {
            case 34: // '"'
                result.append(""");
                break;

            case 38: // '&'
                result.append("&");
                break;

            case 39: // '\''
                result.append("'");
                break;          

            case 60: // '<'
                result.append("<");
                break;

            case 62: // '>'
                result.append(">");
                break;

            default:
                result.append(content[i]);
                break;
            }
        }
        return result.toString();
    }

你可能感兴趣的:(java)