2 Replies - 8254 Views - Last Post: 13 October 2010 - 01:14 AM Rate Topic: -----

#1 ilareF  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-October 10

how to read a specific word in a text file using c sharp language in a

Posted 12 October 2010 - 06:04 PM

ilareF
Good day everyone!

I'm currently working on a project and i need to open a text file and read a specific word.

As of now, i already know how to open a text file but my problem is i don't know how to read a specific word in a text file. (I know how to read a line but not a specific word)

I have three textbox and two buttons. the first textbox displays the content of the text file that i opened.

what i want to do is when i type a specific word in the second textbox it will appear on the third textbox if the word exists in the text file that i opened but if not a message box will pop out with a message "The word that you typed is not in the textfile".

Please help me... I'm new in c sharp language and i'm new in making projects at asp.net 3.5 windows application...



My project is called Data Capturing..

Thanks for the help


i attached the screen shot of my form..
Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: how to read a specific word in a text file using c sharp language in a

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: how to read a specific word in a text file using c sharp language in a

Posted 12 October 2010 - 06:27 PM

well since you already know how to get the string then one way to search the string for a value is by doing a Regex match. You can read up on it here.

Edit: Another possibility is to look into the contains method of the string class here.

This post has been edited by Nakor: 12 October 2010 - 06:34 PM

Was This Post Helpful? 0
  • +
  • -

#3 Zdrenka  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 116
  • Joined: 24-November 09

Re: how to read a specific word in a text file using c sharp language in a

Posted 13 October 2010 - 01:14 AM

have you tried using IndexOf? something like this maybe:

StreamReader reader = new StreamReader(@"C:\file.txt", System.Text.Encoding.Default);
            string Text = reader.ReadToEnd();

            int lineIndex = Text.IndexOf(textBox2.Text);
            if (lineIndex == -1)
            {
                textBox3.Text = lineIndex;

            }
            else
            {
                MessageBox.Show("The word that you typed is not in the textfile");
            }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1