Comparing strings and get the first place where they vary from eachother

后端 未结 8 1129
滥情空心
滥情空心 2020-12-16 11:07

I want to get the first place where 2 string vary from each other. example: for these two strings: \"AAAB\" \"AAAAC\"

I want to get the result 4.

How do i d

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 11:51

    static void Main(string[] args)
    {
        Console.WriteLine("enter s1 :");
        string s1 = Console.ReadLine();
        Console.WriteLine("enter s2 :");
        string s2 = Console.ReadLine();
    
        Console.WriteLine("note: zero means there is *no* first dif index starting from s1 ");    
        Console.WriteLine("first dif index of s1 :{0}", findFirstDifIndex(s1, s2)+1);
    }
    
    private static int findFirstDifIndex(string s1, string s2)
    {
        for (int i = 0; i 

提交回复
热议问题