Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am doing a simple search on Richtext box, using web form application
I created a "Search" button, TextBox and a RichtextBox
I need to eliminate these word from user typing in the search box
The words are

(the, and, of, to, that, in, he, shall, for, unto, i, his, a, they, be, is, not, him, them, it, with, all, thou, was, thy, which, my, me)

The Code is:
C#
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;

namespace search_bar_w_richtextbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int index = 0;
            while (index < richTextBox1.Text.LastIndexOf(textBox1.Text))
            {
                richTextBox1.Find(textBox1.Text, index, richTextBox1.TextLength, RichTextBoxFinds.None);
                richTextBox1.SelectionBackColor = Color.Green;
                index = richTextBox1.Text.IndexOf(textBox1.Text, index) + 1;
            }
        }
    }
}


If any one know how to eliminate those word from user typing,
Can you post the full Code !!!!
Posted
Updated 19-Feb-13 14:20pm
v2
Comments
TRK3 19-Feb-13 20:23pm    
Do you want to stop the user from actually typing those words?

Or would you be satisfied with removing them from whatever he typed after he clicks on the search button (before you actuall search)?

1 solution

Store these works in a dictionary or list.
Parse the string typed in the text box and replace any of these characters with a bland.

A simple Linq query or even a string.Replace[^] would work.

For more complex pattern matching you can look at a RegEx[^] replace.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900