locked
compare two strings and show the difference in asp.net RRS feed

  • Question

  • User1910487977 posted

    I would like to compare my 2 textbox string and shows the difference between those 2 word.

    Eg:

    Textbox1 : Kareem Khan

    Textbox2 : Karem Khan

    Result : Karem Khan - e is missing

    Textbox1 : Kareem Khan

    Textbox2 : Kareema Khan

    Result : Kareema Khan - a is extra word

    Saturday, November 2, 2019 4:18 AM

All replies

  • User-474980206 posted

    You will need a difference engine. Google for one of your choice. There are several ports of the google diff engine. Try

    https://github.com/mmanela/diffplex

    Saturday, November 2, 2019 5:42 PM
  • User-1780421697 posted
    class Program
        {
            static void Main(string[] args)
            {
    
                string s1 = "string1";
                string s2 = "stringa1";
    
                char[] c1 = s1.ToCharArray();
                char[] c2 = s2.ToCharArray();
    
                var diff = s1.Except(s2);
                string newS1 = s1;
                foreach(var value in diff)
                {
                    newS1 = newS1.Replace(value, '*');
                    Console.WriteLine(value);
                }
                Console.WriteLine(newS1);
                Console.Read();
            }
        }

    Saturday, November 2, 2019 8:37 PM