We help IT Professionals succeed at work.
Get Started

clearing a bad word in a global setting

r3nder
r3nder asked
on
528 Views
Last Modified: 2012-05-09
I have a class that checks for bad words - on pressing the enter key or the button in the application it is running in it throws an alert that says it is a bad word. now this is global so any app running- like notepad - if you are typing a bad word in is effected by it-  how do I clear that bad word or change the bad word to hash marks (####)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Management;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using System.Security;
using System.Runtime.InteropServices;


namespace Nomad
{
    public partial class frmMain : Form
    {
        BadWordFilter newBadwordFilter;
       
        public frmMain()
        {
            InitializeComponent();
            comboBox1.SelectedIndex = 0;
            newBadwordFilter = BadWordFilter.Instance;
            InterceptKeys.AttachHook(); <- this starts the bad word process
            //bool a = which one
            //a = newBadwordFilter.IsCleanString("Fuck");//to check
            //a = newBadwordFilter.IsCleanString("Duck");//to check
            int c = 0;
           


        }
       
   



        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            webBrowser1.Navigate(new Uri(comboBox1.SelectedItem.ToString()));

        }

        private void btnStartLP_Click(object sender, EventArgs e)
        {

            var proc = new Process();
            proc.StartInfo.FileName = "chat/chat.exe";
            proc.StartInfo.Arguments = "-v -s -a";
            proc.Start();
            proc.WaitForExit();
            var exitCode = proc.ExitCode;
            proc.Close();
        }
        ///////////////////////////////Knowledge  Base//////////////////
        /// <summary>
        /// Question answer Pair
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///
        private void btnSearchKnowledge_Click(object sender, EventArgs e)
        {
            char[] delimiters = new char[] { ',', ' ' };
            string[] keywords = txtBoxKnowledgeQuestion.Text.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            XmlDocument doc = new XmlDocument();
            doc.Load("XMLQandA.xml");

            XmlElement root = doc.DocumentElement;

            XmlNodeList nodeList = root.SelectNodes("/messages/messageItem");

            foreach (XmlNode node in nodeList)
            {
                bool hasAllWords = true;
                bool hasAnyWord = false;
                foreach (string keyword in keywords)
                {
                    if (node.InnerText.Contains(keyword))
                    {
                        hasAnyWord = true;
                    }
                    else hasAllWords = false;
                }


                if (hasAllWords)
                {
                    // add the node to found-items-list        
                    lstBoxQA.Items.Add(node.InnerText);
                    lstBoxQA.Items.Add("======================");
                    //lstBoxQA.Items.AddRange(node.InnerText);
                    return;

                }
                if (hasAnyWord)
                {
                   

                    //process found-items-list
                    lstBoxQA.Items.Add(node.InnerText);
                    lstBoxQA.Items.Add("======================");
                    //lstBoxQA.Items.AddRange(node.InnerText);
                   
                }
                               

               

            }
            //frmWarning frm = new frmWarning();
            //frm.Show();
            MessageBox.Show("You have typed a word that has been deemed \n inapropriate - it will be blanked out - Next time an email \n will be sent to HR and IT to have your access cut off"); <-this is the test area          
            int c = 1;
        }

        private void btnEVid_Click(object sender, EventArgs e)
        {
            webBEVid.Navigate(new Uri("http://172.0.0.1//Login.aspx"));
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnLogon_Click(object sender, EventArgs e)
        {
           
           
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
           
        }

        private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
           
        }

        private void btnCamp_Click(object sender, EventArgs e)
        {
            webBrowser2.Navigate(new Uri("http://et2app01/Ensercle/index.htm"));
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            lstBoxQA.Items.Clear();
            txtBoxKnowledgeQuestion.Clear();
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            InterceptKeys.DetachHook(); <- this ends the bad word process
        }
       
       
    }
}
Comment
Watch Question
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 21 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE