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

  • SEARCH
  • Home
  • 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 7966513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:26:53+00:00 2026-06-04T06:26:53+00:00

I have two hashsets that are loading data from two different text files. The

  • 0

I have two hashsets that are loading data from two different text files.
The contents of both text files look as follows:

name/12441431252132
name1/323244231244142
name2/32423452524234

My code to currently load both files and make sure i only have unique results from textFile2:

HashSet<string> txt1 = new HashSet<string>(File.ReadLines("textFile1.txt"));
HashSet<string> txt2 = new HashSet<string>(File.ReadLines("textFile2.txt"));

txt2.ExceptWith(txt1); 

My problem is that it only removes lines based on the criteria if the whole line matches. I want to remove It based on the name basis instead. For example, name2 should never be included if its in textFile1 even if the id’s after the / are different.

How would i accomplish this?

Let me know if my explanation is not good i will try to improve it – and please excuse my english!

  • 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-06-04T06:26:55+00:00Added an answer on June 4, 2026 at 6:26 am

    You can just add some string splitting to separate names and the rest of the content – the approach is a little “dirty” so in real code I would probably use foreach loops and introduce dedicated classes:

    var content = File.ReadLines("textFile1.txt").Select(line => 
    {
        var parts = line.Split('/');
        return new 
        { 
            Name = parts[0],
            Content = parts[1]
        };
    });
    
    HashSet<string> names = new HashSet<string>(content.Select(c=> c.Name));
    HashSet<string> txt2 = new HashSet<string>(File.ReadLines("textFile2.txt"));
    var uniques = txt2.Where(line => !names.Contains(line.Split('/')[0]));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes generated by LINQ2SQL both from the same table so they
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have a C#-Application that stores data from a TextFile in a Dictionary-Object. The
Assume that I have two entities as follows: class Blog { public Blog() {
Have two folders with approx. 150 java property files. In a shell script, how
I have two application that need to talk to each other. App1 needs to
I have a class that contains a collection. The two instances of the class
I have a text file that contains very long lines. I need one piece
I have two Maps that contain the same type of Objects: Map<String, TaskJSO> a
I have two folders A and B..inside that two folders lots of folders and

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.