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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:47:28+00:00 2026-06-05T00:47:28+00:00

I have a list of objects: e.g. A, A, B, C, D, E, E

  • 0

I have a list of objects:
e.g. A, A, B, C, D, E, E

And I have defined templates that tell how object types can be grouped
e.g.

 Group Alpha --> A 1..n --> any number of 'A's can be grouped
 Group Charlie --> Sequences of 'BCD' can be grouped
 Group Epsilon --> E 1..n --> any number of 'E's can be grouped

Now I want to apply those group definitions on the original list, which should give the result:

 Group Alpha (2x'A'), Group Charlie (1x'BCD'), Group Epsilon (2x'E')

How can this be best achieved? Is there a known search algorithm/pattern for my issue?
I have tried a very basic way of looping many times over the list and trying to look ahead from each list entry and match patterns but was totally lost due to the complexity …

Thanks in advance for any hint !!!

  • 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-05T00:47:30+00:00Added an answer on June 5, 2026 at 12:47 am

    I am not completely sure that this is what you need but with this small code I can create the output you specified

    Simple usage (with assertions):

    var a1 = new List<string> { "A", "A", "B", "C", "D", "E", "E" };
    
    a1.ApplyCriteria("A").Criteria.Should().Be("A");
    a1.ApplyCriteria("A").Count.Should().Be(2);
    
    a1.ApplyCriteria("E").Criteria.Should().Be("E");
    a1.ApplyCriteria("E").Count.Should().Be(2);
    
    a1.ApplyCriteria("BCD").Criteria.Should().Be("BCD");
    a1.ApplyCriteria("BCD").Count.Should().Be(1);
    
    a1.ApplyCriteria("CD").Criteria.Should().Be("CD");
    a1.ApplyCriteria("CD").Count.Should().Be(1);
    
    // not found
    a1.ApplyCriteria("CDA").Criteria.Should().Be("CDA");
    a1.ApplyCriteria("CDA").Count.Should().Be(0);
    

    My GroupResult class returned by the ApplyCriteria method looks like:

    class GroupResult
    {
        public string Criteria { get; set; }
        public int Count { get; set; }
    }
    

    And these are the extension methods that are doing the real work

    static class Ext
    {
        public static GroupResult ApplyCriteria(this IEnumerable<string> source, string criteria)
        {
            var elements = source.ToConcatenedString();
    
            return new GroupResult { Criteria = criteria, Count = elements.CountOcurrences(criteria) };
        }
    
        public static int CountOcurrences(this string source, string phrase)
        {
            return source
                .Select((c, i) => source.Substring(i))
                .Count(sub => sub.StartsWith(phrase));
        }
    
        public static string ToConcatenedString<TSource>(this IEnumerable<TSource> source)
        {
            var sb = new StringBuilder();
    
            foreach (var value in source)
            {
                sb.Append(value);
            }
    
            return sb.ToString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of objects that I want to query using LINQ. I
I have a list of objects.Every object has an attribute priority whose value could
I have a list of objects (Foo). A Foo object has several attributes. An
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have 2 List objects: List<int> lst1 = new List<int>(); List<int> lst2 = new
I have List where myObj has it own list of objects called example mySubObj.
I have a list of objects and need to get the list of records
I have a list of objects I'm referring to as Artifacts. I need to
I have a list of objects which I need to store in a dictionary.
I have a list of objects and i want to bind this list with

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.