怎样让自己的网站避免暴力,肮脏的词语袭击?过滤用户提交的数据显得尤为重要。下面是一个非常简单的过滤方法。
public class WordsFilter { public string[] filterWords; private string replaceWords; /// /// 添加过滤词汇 /// /// 过滤目标(以逗号隔开) /// 替换词 public void InsertFilterWords(string words,string replaceWords) { this.replaceWords = replaceWords; filterWords = words.Split(','); } /// /// 过滤,返回过滤后的字符串 /// /// /// public string Filter(string msg) { for (int i = 0; i < filterWords.Length; i++) { msg=msg.Replace(filterWords[i], replaceWords); } return msg; } }
添加要过滤的词汇
调用Filter方法过滤内容,返回过滤后的内容。
彭亚欧个人博客原创文章,转载请注明出处
文章关键词:C#字符串替换,C#脏话过滤,屏蔽脏话
文章固定链接:https://www.pengyaou.com/homeart/MTEy.html
上一篇 你来问,我们来答
下一篇 互联网大佬们的流氓行为