Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 249913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:28:02+00:00 2026-05-11T21:28:02+00:00

I got richtextBox control in form and a text file. I am getting text

  • 0

I got richtextBox control in form and a text file. I am getting text file to array and getting richtextbox1.text to other array than compare it and count words matching.

But for example there are two “name” word in text file and three “and” word in richtextbox. So if there is two same word in text file in richtextbox it cant be 3 or higher after 2, it must be wrong word so it must not be counted. But HashSet is counting unique values only not looking for duplicates in text file. I want to compare every word in text file with words in RichTextBox.

My code is here:

        StreamReader sr = new StreamReader("c:\\test.txt",Encoding.Default);
        string[] word = sr.ReadLine().ToLower().Split(' ');
        sr.Close();
        string[] word2 = richTextBox1.Text.ToLower().Split(' ');
        var set1 = new HashSet<string>(word);
        var set2 = new HashSet<string>(word2);
        set1.IntersectWith(set2);

        MessageBox.Show(set1.Count.ToString());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:28:02+00:00Added an answer on May 11, 2026 at 9:28 pm

    Inferring that you want:

    file:

    foo
    foo
    foo
    bar
    

    text box:

    foo
    foo
    bar
    bar
    

    to result in ‘3’ (2 foos and one bar)

    Dictionary<string,int> fileCounts = new Dictionary<string, int>();
    using (var sr = new StreamReader("c:\\test.txt",Encoding.Default))
    {
        foreach (var word in sr.ReadLine().ToLower().Split(' '))
        {
            int c = 0;
            if (fileCounts.TryGetValue(word, out c))
            {
                fileCounts[word] = c + 1;
            }
            else
            {
                fileCounts.Add(word, 1);
            }                   
        }
    }
    int total = 0;
    foreach (var word in richTextBox1.Text.ToLower().Split(' '))
    {
        int c = 0;
        if (fileCounts.TryGetValue(word, out c))
        {
            total++;
            if (c - 1 > 0)
               fileCounts[word] = c - 1;                
            else
                fileCounts.Remove(word);
        }
    }
    MessageBox.Show(total.ToString());
    

    Note that this is destructively modifying the read dictionary, you can avoid this (so only have to read the dictionary once) buy simply counting the rich text box in the same way and then taking the Min of the individual counts and summing them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 192k
  • Answers 192k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Two tables means 40% of your queries have joins and… May 12, 2026 at 6:21 pm
  • Editorial Team
    Editorial Team added an answer I'm currently working on an Elgg-based site and I absolutely… May 12, 2026 at 6:21 pm
  • Editorial Team
    Editorial Team added an answer I'm assuming you mean out of the box. If so,… May 12, 2026 at 6:21 pm

Related Questions

Is there any light version of richtextbox control? I've got to create like 300+
I've built a dialogbox with a RichTextBox and I'd like to have the following
I've got some backgroundworker threads that are working on calculations or saving data. Every
I'm looking for a good ASP.NET RichTextBox component that integrates fairly easily with .NET

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.