In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
TrieFilter class
Using System
Using System.Collections.Generic
Using System.Linq
Using System.Web
Namespace SaaS.Web.Base
{
Public class TrieNode
{
Public bool m_end
Public Dictionary m_values
Public TrieNode ()
{
M_values = new Dictionary ()
}
}
Public class TrieFilter: TrieNode
{
/ / /
/ / add keyword
/ / /
/ / /
Public void AddKey (string key)
{
If (string.IsNullOrEmpty (key))
{
Return
}
TrieNode node = this
For (int I = 0; I < key.Length; iTunes +)
{
Char c = key [I]
TrieNode subnode
If (! node.m_values.TryGetValue (c, out subnode))
{
Subnode = new TrieNode ()
Node.m_values.Add (c, subnode)
}
Node = subnode
}
Node.m_end = true
}
/ / /
/ check whether it contains illegal characters
/ / /
/ / enter text
/ / the first illegal character found. If not, return string.Empty.
Public bool HasBadWord (string text)
{
For (int I = 0; I < text.Length; iTunes +)
{
TrieNode node
If (m_values.TryGetValue (text [I], out node))
{
For (int j = I + 1; j < text.Length; jacks +)
{
If (node.m_values.TryGetValue (text [j], out node))
{
If (node.m_end)
{
Return true
}
}
Else
{
Break
}
}
}
}
Return false
}
/ / /
/ check whether it contains illegal characters
/ / /
/ / enter text
/ / the first illegal character found. If not, return string.Empty.
Public string FindOne (string text)
{
For (int I = 0; I < text.Length; iTunes +)
{
Char c = text [I]
TrieNode node
If (m_values.TryGetValue (c, out node))
{
For (int j = I + 1; j < text.Length; jacks +)
{
If (node.m_values.TryGetValue (text [j], out node))
{
If (node.m_end)
{
Return text.Substring (I, j + 1-I)
}
}
Else
{
Break
}
}
}
}
Return string.Empty
}
/ / find all illegal characters
Public IEnumerable FindAll (string text)
{
For (int I = 0; I < text.Length; iTunes +)
{
TrieNode node
If (m_values.TryGetValue (text [I], out node))
{
For (int j = I + 1; j < text.Length; jacks +)
{
If (node.m_values.TryGetValue (text [j], out node))
{
If (node.m_end)
{
Yield return text.Substring (I, (j + 1-I))
}
}
Else
{
Break
}
}
}
}
}
/ / /
/ / replace illegal characters
/ / /
/ / /
/ / used to replace illegal characters
/ / replaced string
Public string Replace (string text, char c)
/ / public string Replace (string text, char c ='*')
{
Char [] chars = null
For (int I = 0; I < text.Length; iTunes +)
{
TrieNode subnode
If (m_values.TryGetValue (text [I], out subnode))
{
For (int j = I + 1; j < text.Length; jacks +)
{
If (subnode.m_values.TryGetValue (text [j], out subnode))
{
If (subnode.m_end)
{
If (chars = = null) chars = text.ToArray ()
For (int t = I; t
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.