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 762269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:56:15+00:00 2026-05-14T15:56:15+00:00

What I have going on is two files, one file contains: Orange Apple The

  • 0

What I have going on is two files, one file contains:

Orange
Apple

The second file contains
Orange~1.txt
Orange~2321.txt
Apple~12.txt
Apple~23.txt
Ap~23.txt
OROR~23.txt

What I need to do is is if the first file matches a line in the second file, copy that file out to a new directory. What I have going on now never finds any matching items.

string[] content = File.ReadAllLines(@"C:\Cact.txt");
            string[] mastercontent = File.ReadAllLines(masterdin + "\\Master.txt");
            foreach (string con in content)
            {
                if (mastercontent.Contains(con))
                {
                    File.Copy(masterfolder + "\\" + con, masterdin);
                }
            }
  • 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-14T15:56:15+00:00Added an answer on May 14, 2026 at 3:56 pm

    You’re calling the LINQ Contains method on the array, which will return true if the array contains a string which is exactly equal to con.

    The simplest solution is to change mastercontent to a single string by calling File.ReadAllText.
    This will call String.Contains, and will check whether con appears anywhere in the large string. (This would behave differently if con has newlines, but it can’t)

    Alternatively, you can use LINQ to check whether mastercontent has any strings containing con, like this:

    if (mastercontent.Any(m => m.Contains(con))
    

    EDIT: To match case-insensitively, you can change it to the following:

    if (mastercontent.Any(m => 0 >= m.IndexOf(con, StringComparison.OrdinalIgnoreCase))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have two files, one that contains my text, and another which I
Hey everybody, this is what I have going on. I have two text files.
What I'm trying to do: I have two files: One is the header.php which
I have a text file words.txt that contains english words. Let's assume it contains
So far in this project I have two reports in VS2008/BIDS. The first one
I'm going to have two independent programs (using SqlAlchemy / ORM / Declarative) that
I need to learn couchbd and have been going through tutorials on views. I
I have a bunch of files (on the order of 10 per second) coming
I have two tables that need to be updated, Master and Identifiers: Master --MasterID
I have two sql script file which are to be scheduled as windows tasks.

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.