Skip to content

Find the match between 2 strings

brian dsouza

Asked Mar 10, 2016, 6:43 PM EST1 answer
Share
LinkedInX
hi guys
 
i have 2 strings a="01011"
                           b=" 10110" 
how can i find the location of the first match.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Saillesh Pawar
    0
    I hope this will help.
     
    C#
    {
                string a = "01011";
                string b = "10110";
                //converting into char array
                char[] charArrayA = a.ToCharArray();
                char[] charArrayB = b.ToCharArray();
    
                //logic for comparing the each elements with both the arrays
                for(int i=0;i<charArrayA.Length;i++)
                {
                    if (charArrayA[i] == charArrayB[i])
                    {
                        Console.WriteLine("Match found at location "+(i+1));
                    }
    
                }
                Console.ReadLine();
    
    
            }
     
    0