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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:31:35+00:00 2026-05-30T00:31:35+00:00

I have a string array, which has three fields, which are field1, field2, field3.

  • 0

I have a string array, which has three fields, which are field1, field2, field3.
The length of field1 and field2 are both 1. The length of field3 could be 0 and no limited, usually 0 to 6. What I want to do is when giving field1, field2 and field3 string, find the matched string in arrays. Since the length of field1 and field2 are both 1, they must full matched. But for the field3, as long as it matches one char, it matches.

For example:

  array[0]="AB:CDE"
  array[1]="BA:D"
  array[2]="CA:EFG"
  array[3]="DE:ABEFG"

If I was given three fields string: C, A, FG, then it matches array[2]
D, E, B, it matches array[3]

How to use Linq do the search? Considering the array could in any format.
I’m using c#

  • 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-30T00:31:37+00:00Added an answer on May 30, 2026 at 12:31 am

    I don’t know exactly how you want the results, but here is a method that returns an array of patterns that match your three fields:

    string[] Patterns = new[] { "AB:CDE", "BA:D", "CA:EFG", "DE:ABEFG" };
    string Field1 = "C";
    string Field2 = "A";
    string Field3 = "FG";
    
    string[] Results = MatchPatterns(Patterns, Field1, Field2, Field3);
    
    Console.WriteLine("Matching patterns:");
    foreach (string r in Results)
        Console.WriteLine(r);
    
    private string[] MatchPatterns(string[] patterns, string f1, string f2, string f3)
    {
        return patterns.Where(c => f1 == c.Substring(0, 1) && f2 == c.Substring(1, 1) && c.Substring(3).Contains(f3)).ToArray();
    }
    

    Edit:

    Re-reading your question, I wonder if the pattern CA:EFG was instead CA:EG if that would still match your first three sample fields? You said as long as one character matches in field 3, it should be considered a match.

    This means that if field 3 is FG, since the pattern contains a G it should be a match.

    If this is the functionality you want, replace the above method with this one:

    private string[] MatchPatterns2(string[] patterns, string f1, string f2, string f3)
    {
        return patterns.Where(c => f1 == c.Substring(0, 1) &&
            f2 == c.Substring(1, 1) &&
            c.Substring(3).Any(x => f3.Any(f => f == x))).ToArray();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small array of structs, each struct has three fields, all strings.
I have a string say string s =C:\\Data , I have an array which
I have a .NET string which is Base64 encoded representation of an array of
I have an array of strings in python which each string in the array
I have a String Array which is contain dates that read from a CSV
I have a table:'Categories' which has two fields:Category_ID and Category. Data in Category_ID field
Using C#, I have a List of type Foo, which has a string property
I'm using .NET 3.5. I have two string arrays, which may share one or
I have a two-dimensional array (of Strings) which make up my data table (of
I have a string array in C# and I intend to copy it in

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.