敏感词替换
敏感词替换
String replace(旧值,新值)
需要返回结果
实例
public class 敏感词替换 {
public static void main(String[] args) {
//1.获取说过的话
String talk = "你玩的真好,以后不要再玩了,CNM,NMSL";
//2.定义一个敏感词库
String[] arr = {"CNM","NMSL","SB","MLGB"};
//3.替换敏感词
for (int i = 0; i < arr.length; i++) {
talk = talk.replace(arr[i],"***");
}
//4.打印结果
System.out.println(talk);
}
}