Question : How can I clear the pattern memory after the code returns false

I want to clear the memory after the string is checked and is determined to be a clean string - how do I do that?

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;

/// <summary>
/// Summary description for BadWordFilter
/// </summary>
public class BadWordFilter
{

    /// <summary>
    /// Private constructor and instantiate the list of regex
    /// </summary>
    private BadWordFilter()
    {
        //
        // TODO: Add constructor logic here
        //
        Patterns = new List<Regex>();
    }

    /// <summary>
    /// The patterns
    /// </summary>
    static List<Regex> Patterns;

    private static BadWordFilter m_instance = null;

    public static BadWordFilter Instance
    {
        get
        {
            if (m_instance == null)
                m_instance = CreateBadWordFilter("listofwords.xml");

            return m_instance;
        }
    }

    /// <summary>
    /// Create all the patterns required and add them to the list
    /// </summary>
    /// <param name="badWordFile"></param>
    /// <returns></returns>
    protected static BadWordFilter CreateBadWordFilter(string badWordFile)
    {
        BadWordFilter filter = new BadWordFilter();
        XmlDocument badWordDoc = new XmlDocument();
        badWordDoc.Load(badWordFile);

        //Loop through the xml document for each bad word in the list
        for (int i = 0; i < badWordDoc.GetElementsByTagName("word").Count; i++)
        {
            //Split each word into a character array
            char[] characters = badWordDoc.GetElementsByTagName("word")[i].InnerText.ToCharArray();

            //We need a fast way of appending to an exisiting string
            StringBuilder patternBuilder = new StringBuilder();

            //The start of the patterm
            patternBuilder.Append("(");

            //We next go through each letter and append the part of the pattern.
            //It is this stage which generates the upper and lower case variations
            for (int j = 0; j < characters.Length; j++)
            {
                patternBuilder.AppendFormat("[{0}|{1}][\\W]*", characters[j].ToString().ToLower(), characters[j].ToString().ToUpper());
            }

            //End the pattern
            patternBuilder.Append(")");

            //Add the new pattern to our list.
            Patterns.Add(new Regex(patternBuilder.ToString()));
        }
        return filter;
    }

    /// <summary>
    /// The function which returns the manipulated string
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public string GetCleanString(string input)
    {
        for (int i = 0; i < Patterns.Count; i++)
        {
            //In this instance we actually replace each instance of any bad word with a specified string.
            input = Patterns[i].Replace(input, "####");
        }

        //return the manipulated string
        return input;
    }

    public bool IsCleanString(string input)
    {
        for (int i = 0; i < Patterns.Count; i++)
        {
            //In this instance we actually replace each instance of any bad word with a specified string.
            if (Patterns[i].IsMatch(input))
            {
                return false;
            }
        }

        //return the manipulated string
        return true;
    }
}

Answer : How can I clear the pattern memory after the code returns false

No, you cannot do this. I'm pretty sure that no SQL backup can be restored to any earlier version. If they just want to see the data they could possibly install SQL 2008 R2 Express edition? The compatibility mode does not affect which versions of the SQL engine a database can be restored to.

If that is not an option you will need to look at other technique e.g. replication or use a SSIS package to transfer the data.
Random Solutions  
 
programming4us programming4us