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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:54:16+00:00 2026-05-24T09:54:16+00:00

I have a sorted StringList and wanted to replace foreach (string line3 in CardBase.cardList)

  • 0

I have a sorted StringList and wanted to replace

foreach (string line3 in CardBase.cardList)
            if (line3.ToLower().IndexOf((cardName + Config.EditionShortToLong(edition)).ToLower()) >= 0)
            {
                return true;
            }

with a binarySearch, since the cardList ist rather large(~18k) and this search takes up around 80% of the time.

So I found the List.BinarySearch-Methode, but my problem is that the lines in the cardList look like this:

Brindle_Boar_(Magic_2012).c1p247924.prod

But I have no way to generate the c1p… , which is a problem cause the List.BinarySearch only finds exact matches.

How do I modify List.BinarySearch so that it finds a match if only a part of the string matches?

e. g.
searching for Brindle_Boar_(Magic_2012) should return the position of Brindle_Boar_(Magic_2012).c1p247924.prod

  • 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-24T09:54:18+00:00Added an answer on May 24, 2026 at 9:54 am

    List.BinarySearch will return the ones complement of the index of the next item larger than the request if an exact match is not found.

    So, you can do it like this (assuming you’ll never get an exact match):

    var key = (cardName + Config.EditionShortToLong(edition)).ToLower();
    var list = CardBase.cardList;
    
    var index = ~list.BinarySearch(key);
    return index != list.Count && list[index].StartsWith(key);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have sorted list of strings that I move between php and java. to
I have a sorted collection of objects (it can be either SortedList or SortedDictionary,
I have a sorted dictionary where the key is a date and the value
I'm working in c#. I have a sorted List of structures. The structure has
I have 4 files sorted alphabetically, A, B, C, and D. These files contain
I have a N-Ary non sorted in any way tree and each node can
I have a table of data sorted by date, from which a user can
I have a table where the results are sorted using an ORDER column, eg:
I have a list of items sorted alphabetically: mylist = [a,b,c,d,e,f,g,h,i,j] I'm able to
1-)For sorted array I have used Binary Search. We know that the worst case

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.