我在下面有这些代码,它可以识别您使用 Web 浏览器控件输入的坏词(这些词存储在数据库中)并将其转换为星号 (*)。我一直在努力区分大小写,您可以在其中输入小写或大写(例如:HeLlo)
string query;
query = @"select Word from ListWords";
List<string> words = new List<string>();
DataSet ds;
DataRow drow;
ds = DatabaseConnection.Connection1(query);
int index, total;
total = ds.Tables[0].Rows.Count;
string current_word;
for (index = 0; index < total; index++ )
{
drow = ds.Tables[0].Rows[index];
current_word = drow.ItemArray.GetValue(0).ToString();
words.Add(current_word);
}
Console.WriteLine(query);
Console.WriteLine("array:" + words);
foreach (String key in words)
{
String substitution = "<span style='background-color: rgb(255, 0, 0);'>" + key + "</span>";
int len = key.Length;
string replace = "";
for ( index = 0; index < len; index++)
{
replace += "*";
}
html.Replace(key, replace);
//count++;
}
doc2.body.innerHTML = html.ToString();
}
胡说叔叔