不良词语过滤 (jsp)例子:留言本 

import java.util.StringTokenizer;

/**
* <p>Title: 不良词语过滤</p>
* <p>Description: 不良词语过滤</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: 聚能易成</p>
* Creation date: 04-14-2006
* @author dirboy
* @version 1.0
*/
public class RemoveText {

 public static String[] getStringData(String str, String sign) {
  String[] strData = null;
  StringTokenizer st1 = new StringTokenizer(str, sign);
  strData = new String[st1.countTokens()];
  int i = 0;
  while (st1.hasMoreTokens()) {
   strData[i] = st1.nextToken().trim();
   i++;
  }
  return strData;
 }
 
public static boolean isBadwords(String str){
 boolean result = false;
 str = str.toUpperCase();
 String badwords = ""混蛋|手机|广告";
 String[] data = getStringData(badwords,"|");
 int j = 0;
 for(int i=0;i<data.length;i++){
  int dot = str.indexOf(data[i]);
  if(dot!=-1){
   result = true;
   return result;    
  }
 }  
 return result;
}
 public static void main(String[] args) {
  String str = "手机";
  boolean is = isBadwords(str);
  System.out.println(is); //返回 false 表示含有不良词语
 }
}

 

你可能感兴趣的:(C++,c,jsp,C#,J#)