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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:40:55+00:00 2026-05-26T01:40:55+00:00

In a list with some hundred thousand entries, how does one go about comparing

  • 0

In a list with some hundred thousand entries, how does one go about comparing each entry with the rest of the list for duplicates?
For example, List fileNames contains both “00012345.pdf” and “12345.pdf” and are considered duplicte. What is the best strategy to flagging this kind of a duplicate?

Thanks

Update: The naming of files is restricted to numbers. They are padded with zeros. Duplicates are where the padding is missing. Thus, “123.pdf” & “000123.pdf” are duplicates.

  • 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-26T01:40:55+00:00Added an answer on May 26, 2026 at 1:40 am

    You probably want to implement your own substring comparer to test equality based on whether a substring is contained within another string.

    This isn’t necessarily optimised, but it will work. You could also possibly consider using Parallel Linq if you are using .NET 4.0.

    EDIT: Answer updated to reflect refined question after it was edited

    void Main()
    {
        List<string> stringList = new List<string> { "00012345.pdf","12345.pdf","notaduplicate.jpg","3453456363234.jpg"};
    
        IEqualityComparer<string> comparer = new NumericFilenameEqualityComparer ();
    
        var duplicates = stringList.GroupBy (s => s, comparer).Where(grp => grp.Count() > 1);
    
        // do something with grouped duplicates...
    
    }
    
    // Not safe for null's !
    // NB do you own parameter / null checks / string-case options etc !
    public class NumericFilenameEqualityComparer : IEqualityComparer<string> {
    
       private static Regex digitFilenameRegex = new Regex(@"\d+", RegexOptions.Compiled);
    
       public bool Equals(string left, string right) {
    
            Match leftDigitsMatch = digitFilenameRegex.Match(left);
            Match rightDigitsMatch = digitFilenameRegex.Match(right);
    
            long leftValue = leftDigitsMatch.Success ? long.Parse(leftDigitsMatch.Value) : long.MaxValue;
            long rightValue = rightDigitsMatch.Success ? long.Parse(rightDigitsMatch.Value) : long.MaxValue;
    
            return leftValue == rightValue;
       }
    
       public int GetHashCode(string value) {
            return base.GetHashCode();
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity which shows some List entries. When I click on a
I have a list of <ul> <li>blabla</li> <!-- About 800 or more in some
Could you please list some of the bad practices in SQL, that novice people
I am using a ToolStripComboBox to list some data. I am populating this combo
I'm developing an ASP.Net MVC site and on it I list some bookings from
I heard this today during interview for java developer. I had to list some
Why do argument list in some methods end with nil ? I have noticed
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have a radio button list and some of the labels are quite long
I'm using sphinx to list me some items from my database here. It's almost

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.