Beginner need help!!!!!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Beginner need help!!!!!

  1. #1
    Join Date
    Jan 2013
    Posts
    7

    Beginner need help!!!!!

    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
    Code:
    (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
    but
    their
    said
    ye
    have
    will
    thee
    from
    as
    are
    when
    this
    were
    out
    by
    you
    up
    there
    then
    had
    into
    on
    one
    her
    we
    s
    your
    also
    so
    an
    if
    at
    us
    no
    do
    now
    therefore
    every
    these
    our
    or
    because
    after
    o
    may
    did
    what
    over
    who
    she
    any
    among
    thereof
    neither
    am
    should
    whom
    nor
    thus
    yet
    set
    more
    about
    how
    himself
    than
    other
    ever
    would
    without
    where
    under
    both
    been
    until
    yea
    wherefore
    toward
    well
    only
    such
    very
    between
    above
    yourselves
    cannot
    within
    whosoever
    could
    about
    above
    the
    and
    of
    to
    that
    in
    he
    for
    unto
    i
    his
    a
    they
    be
    is
    not
    him
    them
    it
    with
    all
    thou
    was
    thy
    which
    my
    me
    but
    their
    said
    ye
    have
    thee
    from
    as
    are
    when
    this
    were
    out
    by
    you
    up
    there
    then
    had
    into
    on
    one
    her
    we
    also
    your
    so
    day
    an
    if
    shalt
    at
    let
    go
    us
    do
    these
    or
    our
    say
    hast
    o
    did
    what
    who
    any
    put
    am
    two
    should
    know
    whom
    nor
    thus
    yet
    done
    saw
    how
    than
    off
    art
    three
    other
    those
    would
    first
    where
    both
    been
    yea
    wherefore
    five
    four
    whose
    being
    much
    why
    only
    such
    very
    though
    ten
    can
    therein
    known
    while
    doth
    thyself
    six
    cannot
    third
    twelve
    second
    could
    new
    knew
    wherein
    till
    here
    lo
    able
    throughout
    find
    forty
    fifty
    thence
    must
    get
    ask
    lot
    wherewith
    ought
    threescore
    tenth
    ones
    plain
    whereof
    el)
    The Code is
    Code:
    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 !!!!
    Last edited by BioPhysEngr; February 21st, 2013 at 12:32 AM. Reason: added code tags around the wordlist and fixed the bizarre huge text

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: Beginner need help!!!!!

    The following is a very simple-minded approach. Depending on your purposes, though, it might be enough:

    Code:
    public string sanitizeString(string initial, string[] prohibitedWords)
    {
        string[] tokens = initial.Split(' '); //Split the string into tokens by spaces
        System.Text.StringBuilder result = new System.Text.StringBuilder();
        for(int i = 0; i < tokens.Count; i++)
        {
            //Only add non-prohibited tokens to the result string
            if( !arrayContainsToken(tokens[i], prohibitedWords) )
            {
                result.Append(token[i]);
                result.Append(" ");
            }
        }
    
        return result.ToString();
    }
    
    bool arrayContainsToken(string token, string[] prohibitedWords)
    {
        //Returns true if token is in the list of prohibited words
    }
    Also, try to avoid any clbuttic mistakes: http://www.codinghorror.com/blog/200...-bad-idea.html
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: Beginner need help!!!!!

    Words meaning separated by a space? (Note: you'll have to trim out the delimiters in case someone types in "badword!" for example. "badword" != "badword!". Or in-string values as well? "somethingbadwordsomething"?

    Check using IndexOf() and perhaps check if there is a space before the found word at the index returned by IndexOf() - 1. If at the beginning of the user-input, then keep in mind to not check the index before as 0 - 1 = -1, and -1 would be invalid as an index for a string.

    Can you post the full Code !!!!
    No... I don't write code for others, I just help. We need more clarity however on what your guidelines are, as there's probably many things that you and others have not thought about. If, just anywhere in the string you don't want these words, regardless of their surrounding characters, then IndexOf() would work perfectly.

    Code:
    "String value".IndexOf('v', StringComparison.OrdinalIgnoreCase);
    Use a StringComparison option for case insensitive validation (assuming you want case insensitivity here).

    I am willing to help, but if you just want code, then I'm probably not the right person you're looking for.

    ~Ace
    Last edited by AceInfinity; February 21st, 2013 at 10:50 PM.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center