package cn.edu.hpu.responsibility; public class Main { public static void main(String[] args) { String msg="大家好:),<script>,敏感,和谐,我们要把设计模式学好"; } }
package cn.edu.hpu.responsibility; public class MsgProcessor { private String msg; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String process(){ return ""; } }在Main类中这么使用它:
package cn.edu.hpu.responsibility; public class Main { public static void main(String[] args) { String msg="大家好:),<script>,偷盗,抢劫,我们要把设计模式学好"; MsgProcessor mp=new MsgProcessor(); mp.setMsg(msg); String result=mp.process(); System.out.println(result); } }
package cn.edu.hpu.responsibility; public class MsgProcessor { private String msg; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String process(){ //先处理带尖括号的信息 String r=msg.replace('<', '[') .replace('>', ']'); return r; } }
public String process(){ //先处理带尖括号的信息 String r=msg.replace('<', '[') .replace('>', ']'); //处理敏感字眼 r=r.replace("偷盗", "和谐") .replace("抢劫", "帮助"); return r; }测试Main结果:
加的比较方便呢?
思考........
下一篇总结继续:http://blog.csdn.net/acmman/article/details/44673311
转载请注明出处:http://blog.csdn.net/acmman/article/details/44673243