Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
for ex. string s1=jersey;

string s2=jry;

print using asterisk j*r**y

is there any algorithm to compare two string and then write the diff.
btw I'm using VS C# ASP.net web application

thanks
Posted
Updated 21-Apr-16 21:44pm
v2
Comments
Matt T Heffron 13-Apr-16 20:07pm    
What is the code that you already have?
(You do already have some code to do this, right?! Even if it doesn't work...)
Just show us the part where you tried to find the difference.
The rest should just be "standard" ASP.net to do a web page.
PIEBALDconsult 13-Apr-16 21:29pm    
Do you want the https://en.wikipedia.org/wiki/Levenshtein_distance ?
Or https://en.wikipedia.org/wiki/Approximate_string_matching ?
Sergey Alexandrovich Kryukov 14-Apr-16 1:48am    
I have no idea what "difference" means. I guess, nobody knows unless you explain it precisely. If you formulate it strictly, it will be some 80% of solution, or even more.
—SA
Sergey Alexandrovich Kryukov 14-Apr-16 1:48am    
...
Member 12003400 14-Apr-16 3:21am    
yes provide what kind of difference you needed? You cant to fetch missing character or different characters or case of letter,,can be so many parameters.

With LINQ you can use EXCEPT.
An example is given here Enumerable.Except(TSource) Method (IEnumerable(TSource), IEnumerable(TSource)) (System.Linq)[^]
Make two enumarables from each string (or 2 arrays of char) compare those with EXCEPT.

Example CONSOLE APP:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DiffExcept
{
    class Program
    {
        static void Main(string[] args)
        {

            string s1 = "jersey";
            string s2 = "jry";

            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();
        }
    }
}
 
Share this answer
 
v4
Comments
rkthiyagarajan 22-Apr-16 4:23am    
Wow simply super first time i hear "Except" keyword :-) thanks
I think below code hip you

C#
string s1 = "jersey";
            string s2 = "jry";
            string final = string.Empty;
            char[] aa = s1.ToCharArray();
            foreach (char aaa in aa)
            {
                final = final + "*";
            }
            char[] bb = s2.ToCharArray();
            int startindex=0;
            foreach (char bbb in bb)
            {
                foreach (char aaa in aa)
                {
                    if (s1.IndexOf(bbb, startindex) > -1)
                    {
                        final = final.Remove(s1.IndexOf(bbb, startindex), 1);
                        final = final.Insert(s1.IndexOf(bbb, startindex), bbb.ToString());
                        startindex = s1.IndexOf(bbb, startindex) + 1;
                    }
                    
                }

            }
            Response.Write(final);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900