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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:02:35+00:00 2026-06-04T04:02:35+00:00

UPDATE: As @Blender pointed out in Python set(‘aab’).issubset(set(‘abb’)) == True . For my situation

  • 0

UPDATE:

As @Blender pointed out in Python set('aab').issubset(set('abb')) == True. For my situation this needs to return false. The number of each character needs to be taken into account.


Basically I have two strings and I would like to determine if one is a subset of another. Example:

String A: abcd
String B: dbace
String A is a subset of string B

Characters can be in any order and there can be repeating numbers of characters. I had tried ordering the strings and then using String.StartsWith, but this does not work in certain situations. Example:

String A: abcdd
string B: abbcdd
Ordering these and using StartsWith returns false because string B has two "b"s

I did some looking around and found Python’s issubset method which appears to do what I want, so I’m curious if anyone has come across its equivalent in .NET (or an effective method someone has come up with on their own).

NOTE: I am looking for subsets, not anagrams.

  • 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-04T04:02:36+00:00Added an answer on June 4, 2026 at 4:02 am

    There’s nothing built-in that I know of that behaves as you want it. Strictly speaking, this isn’t a real subset as it should be doing set comparisons as it is in Python (where every item in a set is unique) but it should be simple to cook one up.

    public static bool IsSubsetOf<TSource>(this IEnumerable<TSource> lhs, IEnumerable<TSource> rhs)
    {
        // O(m+n)
        var contents = rhs.ToList();
        foreach (var item in lhs)
        {
            if (!contents.Remove(item))
                return false;
        }
        return true;
    }
    
    "aab".IsSubsetOf("abb");      // false
    "foo".IsSubsetOf("food");     // true
    "foo".IsSubsetOf("goof");     // true
    "bar".IsSubsetOf("barf");     // true
    "abcd".IsSubsetOf("dbace");   // true
    "abcdd".IsSubsetOf("abbcdd"); // true
    

    If you want true set mechanics, it is just as simple.

    public static bool IsTrueSubsetOf<TSource>(this IEnumerable<TSource> lhs, IEnumerable<TSource> rhs)
    {
        return new HashSet<TSource>(lhs).IsSubsetOf(rhs);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: This is, as I was told, no principle Python related problem, but seems
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
UPDATE mytable SET this = 'this' AND that = 'that' WHERE MATCH (items) AGAINST
UPDATE : I got my O3D situation straightened out, but I have yet to
Update: As someone pointed out I was missing an s in my Route registration.
Update: This does work, I was being stupid :( i have the following extension
Update Putting this at the top because it is crazy :) So some users
I found this simple jquery plugin from jQuery Set Cursor Position in Text Area
UPDATE: Solution at bottom. I recently switched from using a set up such as
UPDATE: An idea to make built-in strings non-iterable was proposed on python.org in 2006

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.