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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:56:16+00:00 2026-06-08T02:56:16+00:00

Just like in the title. I got one array of strings and second array

  • 0

Just like in the title. I got one array of strings and second array of strings. I want to display result in this kind of pattern: first element of the first array – then all elements from second array that occurs in first element of first array. After that second element of first array and all elements from second array that occurs in second element of first array. And so on.
For example:

string[] arrayA = {"Lorem ipsum dolor sit amet, justo", "notgin like good cold beer"};
string[] arrayB = {"justo","beer","lorem"}
for (int i = 0; i < arrayA.Length; i++)
   {
      Console.WriteLine(arrayA[i]);

       for (int j = 0; j < arrayB.Length; j++)
       {
          int controlIndex = arrayA[i].IndexOf(arrayB[j]);
          if (controlIndex != -1)
          {
               Console.Write(" :--contains-->" + arrayB[j]);
          }

    }

}

So the result should looks like this:

  • Lorem ipsum dolor sit amet, justo :–contains–> justo,lorem
  • notgin like good cold beer :–contains–> beer.

But mine result is:
– Lorem ipsum dolor sit amet, justo :–contains–> justo
– notgin like good cold beer :–contains–> beer.

So as you can see there is no lorem listed

  • 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-08T02:56:17+00:00Added an answer on June 8, 2026 at 2:56 am

    This is not hard at all if you break your problem down some. First of all, get away from dealing with arrays and indexes into them. Just use IEnumerable<T>, it will make your life easier.

    Here’s how I see it:

    First, you want to find all strings from an array needles, that are part of a string, haystack.

    public static IEnumerable<string> MatchingStrings(string haystack, IEnumerable<string> needles)
    {
        return needles.Where(needle => haystack.Contains(needle));
    }
    

    This will return an IEnumerable of all of the strings from needles that are a part of haystack.

    Then, you want to simply iterate over all of your search strings, I’ll call that haystacks.

        static void Main(string[] args)
        {
            var haystacks = new[] {
                "Lorem ipsum dolor sit amet, justo",
                "notgin like good cold beer"
            };
    
            var needles = new[] {"justo", "beer", "lorem"};
    
            foreach (var haystack in haystacks) {
                Console.Write(haystack + "  contains --> ");
                var matches = MatchingStrings(haystack, needles);
    
                Console.WriteLine(String.Join(",", matches));
            }
    
            Console.ReadLine();
        }
    

    Note that String.Contains() is case-sensitive. So “Lorem” will not match “lorem”. If you want this behavior, you will have to convert them to lowercase first.

    public static IEnumerable<string> MatchingStringsCaseInsensitive(string haystack, IEnumerable<string> needles)
    {
        var h = haystack.ToLower();
        return needles.Where(needle => h.Contains(needle.ToLower()));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just like in the title. I got GridView control that displaying some data from
first I got JSON data via web server just like $.getJSON(url,function(){ //my callback function;
So, just like the title says, I need to create an application that gets
As in title users Just can't get the like button to work properly on
Just like in this topic , I have a performance issue in dev mode
I just got done working through the Django tutorials for the second time, and
just want to ask anyone here can solve this problem? I want to create
I did a quick Google on the title and got pummelled with all this
Sorry for the vague title, but not quite sure how to summarize this one.
Alright, I've got this blank array of objects. I am dynamically finding every node

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.