java处理特殊符号

java类

package com.bean;

public class Change {
    public String ChangeText(String text){
        char[]cs=text.toCharArray();
        StringBuffer sb = new StringBuffer();
        for(int i = 0 ; i             char c = cs[i];
            if(c==' '){
                sb.append(" ");
            }else if(c=='\n'){
                sb.append("
");
            }else if(c=='>'){
                sb.append(">");
            }else if(c=='<'){
                sb.append("<");
            }else if(c=='&'){
                sb.append("&");
            }else{
                sb.append(c);
            }
        }

        return sb.toString();
    }

}

如果还有没有别的没有写上去请留言谢谢

你可能感兴趣的:(java)