19.text--敏感词替换
敏感词替换
将一些固定的词语替换成
使用String replace(旧值,新值)替换
注意点:只有返回值才是替换后的结果
public static void main(String[] args) {
String talk = "TMD";
//定义一个敏感词库
String[] arr = {"TMD","CNM","SB","MLGB"};
//循环得到数组中的每一个敏感词,依次进行替换
for (int i = 0; i < arr.length; i++) {
talk = talk.replace(arr[i], "***");
}
//替换TMD为***
System.out.println(talk);
}