我有一个弹出窗口供用户对视频发表评论。在人们输入消息的表单中,有一个亵渎过滤器。如果它在消息中,它可以正常工作并捕捉到单词。我的问题是,是否有一种方法可以突出显示捕获的单词,以便用户可以看到哪个单词被认为是亵渎的?
这是正在形成并通过过滤器的消息:
if (context.Request["postform"] == "1")
{
ProfanityFilter filter = new ProfanityFilter();
// IF NEITHER THE MESSAGE OR FIRSTNAME CONTAINS ANY PROFANITY IN THEM
if (filter.containsProfanity(context.Request["message"]) == false && filter.containsProfanity(context.Request["first_name_submitter"]) == false)
{
videomessage myVideoMessage = new videomessage();
myVideoMessage.video_id = context.Request["video_id"];
myVideoMessage.first_name_submitter = context.Request["first_name_submitter"];
myVideoMessage.last_initial_submitter = context.Request["last_initial_submitter"];
myVideoMessage.message = context.Request["message"];
myVideoMessage.status = "0";
myVideoMessage.Save();
return_success = "1";
}
else
{
return_success = "0";
return_errormessage = "<span>Contains profanity</span>";
}
}
这是 ProfanityFilter 类:
public class ProfanityFilter
{
// ***********************************************************************
// CONSTRUCTORS
public ProfanityFilter()
{
}
// ***********************************************************************
// ************************************************************************
// METHOD: containsProfanity
public bool containsProfanity(string checkStr)
{
bool badwordpresent = false;
string[] inStrArray = checkStr.Split(new char[] { ' ' });
string[] words = this.profanityArray();
// LOOP THROUGH WORDS IN MESSAGE
for (int x = 0; x < inStrArray.Length; x++)
{
// LOOP THROUGH PROFANITY WORDS
for (int i = 0; i < words.Length; i++)
{
// IF WORD IS PROFANITY, SET FLAG AND BREAK OUT OF LOOP
//if (inStrArray[x].toString().toLowerCase().equals(words[i]))
if( inStrArray[x].ToLower() == words[i].ToLower() )
{
badwordpresent = true;
break;
}
}
// IF FLAG IS SET, BREAK OUT OF OUTER LOOP
if (badwordpresent == true) break;
}
return badwordpresent;
}
// ************************************************************************
// ************************************************************************
// METHOD: profanityArray()
// METHOD OF PROFANITY WORDS
private string[] profanityArray()
{
string[] words = { // ARRAY OF WORDS };
return words;
}
}
有没有办法在中添加一些东西else
来突出显示这个词?或者甚至只是将其颜色从黑色变为红色?
先感谢您!