62,614
社区成员
发帖
与我相关
我的任务
分享
String badWords = "fuck/kao";
String content = "我喜欢fuck";
String result = "";
String words[] = badWords.split("/");
for (int i = 0; i < words.length; i++)
{
result=content.replaceAll(words[i], "***");
}
//result=content.replaceAll("fuck", "***");
System.out.println(result);
result=content.replaceAll("fuck", "***");
配皮和替换成功,此时result="我喜欢***"
result=content.replaceAll("kao", "***");
这句话相当于
result=Pattern.compile(regex).matcher(content).replaceAll(repl)
由于Pattern.compile(regex).matcher(content)匹配不成功,所以最后result=content=我喜欢fuck
tring badWords = "fuck/kao";
String content = "我喜欢fuck";
String result = "";
String words[] = badWords.split("/");
for (int i = 0; i < words.length; i++)
{
content=content.replaceAll(words[i], "***");
}
System.out.println(content);