java笔记-处理特殊字符效果

2012-11-08  付民 

package com.filter;

public class MsgPro {
private String msg;
public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
public String process(){
//处理特殊字符
String r = msg.replace("<", "A-")
             .replace(">", "-A"); //链式编程方法处理字符
//处理敏感词
r = r.replace("fa long gong", "广播体操")
    .replace("狗日的", "小日本");
return r;
}


}
----------------------------------------------------------------------------------------
package com.filter;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
String msg = "hello,<script>,今天天气不错啊...看见一个狗日的fa long gong疯子!";
MsgPro mp = new MsgPro();
mp.setMsg(msg);
String result = mp.process();
System.out.println(result);
}

}

----------------------------------------------------------------------------------
打印效果:

366°/3669 人阅读/0 条评论 发表评论

登录 后发表评论