栗子:最后回到前面的问题:敏感词检测
代码实现:
#region [敏感字符类]
public class SensitiveWorld : Dictionary
{
public bool isLast = false;
public SensitiveWorld AddNode(char word)
{
SensitiveWorld node;
if(!TryGetValue(word, out node))
{
node = new SensitiveWorld();
Add(word, node);
}
return node;
}
public SensitiveWorld GetNode(char word)
{
SensitiveWorld node;
TryGetValue(word, out node);
return node;
}
}
#endregion
static SensitiveWorld sensitiveNodes = new SensitiveWorld();
public static void InitSensitiveWorld(string world)
{
if (string.IsNullOrEmpty(world))
return;
SensitiveWorld node = sensitiveNodes.AddNode(world[0]);
for(int i = 1;