There is a list of forbidden words (or lines that should be more general) and another list with which you can send messages to users. I would like to send all forbidden words from all letters.
Trivial example:
foreach(string word in wordsList) { foreach(string mail in mailList) { mail.Replace(word,String.Empty); } }
How can I improve this algorithm?
Thanks for the tips. I voted for a few answers, but I did not notice any answers, as this was more like a discussion than a solution. Some people have missed forbidden words with bad words. In my case, I donβt have to worry about recognizing βsh1tβ or anything like that.
RegEx, :
var bannedWords = @"\b(this|is|the|list|of|banned|words)\b"; foreach(mail in mailList) var clean = Regex.Replace(mail, bannedWords, "", RegexOptions.IgnoreCase);
, , , .
. .
, "", ""? , - "a $$" - , ?
. ? .
, (FSM) ( ), 1 .
, char , . FSM .
Windows Workflow Foundation: State Machine Workflows.
, .
(word1|word2|word3|...), , . , " ", (\b(word1|word2|word3|...)\b).
word1|word2|word3|...
\b(word1|word2|word3|...)\b
, , , , : , , .
:
, HashSet . Regex Replace, , .
Regex
Replace
HashSet<string> BannedWords = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase) { "bad", }; string Input = "this is some bad text."; string Output = Regex.Replace(Input, @"\b\w+\b", (Match m) => BannedWords.Contains(m.Value) ? new string('x', m.Value.Length) : m.Value);
* , , -, , . , , , "Grand ******* of Normandy", , , , , " "" , ( ), , .
*
Grand ******* of Normandy"
, . 4chan, yahoo , medireview mediareview , eval ( , XSS, yahoo) (apparantly, medireview - !).
: :
u SortedList, ur ( u ";" ), :
ur: Words: n item. ( O (1)). : K item. Z. Y, m = Z/Y.
ur O (n * K * Z).// knut
1. , u O (n log n).
2.1 - mailingListItem.Split( ";". ToCharArray()) : O (Z). 2.2 - : O (m * log m) O (K * Z) (m logm < Z).
3 - : O ((m + n) * k)
O ((m + n) * K + m * Z + n ^ 2) m < n, O (n ^ 2 + Z * K) , O (n * K * Z), n < K * Z (, ).
, , .
Regex , . Regex , , . :
"\bBADWORD\b"
, mailList .
( ) , * - ? , , , , , .
, , , , clbuttic string.Replace(), . , , ( , , ). ... , , - .
, , " " . -,
/ -
, ( ) (, p [ass]). HashSet , , HashSet. , StringBuilder ( ).
, codeproject.com , .