How to check whether two strings contain same characters in same order in C#

1 Answer

0 votes
using System;
using System.Linq;
  
class Program
{
    static bool contain_same_characters_and_order(string s1, string s2) {
        string s1_tmp =  new string(s1.ToCharArray().Distinct().ToArray());
        string s2_tmp =  new string(s2.ToCharArray().Distinct().ToArray());
  
        return s1_tmp == s2_tmp;
    }
    static void Main() {
        string s1 = "c# programming";
        string s2 = "c#### ppprooooooogramminggg";
  
        if (contain_same_characters_and_order(s1, s2))
            Console.Write("yes");
        else
            Console.Write("no");
    }
}
    
    
    
/*
run:
    
yes
    
*/

 



answered Oct 29, 2019 by avibootz
edited Oct 31, 2019 by avibootz

Related questions

...