Compare the similarity of 2 given addresses

Jonathan 380 Reputation points
2026-09-29T03:59:32.17+00:00

Hi,

The way below is good to compare the similarity of 2 given addresses? We expect to achieve that while 80% of the words (in the different position) are appearing well within both strings. Possible to achieve that? Or any other better to do that?

User's image

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Senthil kumar 2,500 Reputation points
    2026-09-29T05:20:14.99+00:00

    Hi @Jonathan

    Please try the below method will achieve the your result.

    public static double WordMatchPercentage(string a, string b)
    {
     var words1 = a.ToLower().Split(' ', ',', '.')
     .Where(x => !string.IsNullOrWhiteSpace(x))
     .ToHashSet();
     
     var words2 = b.ToLower().Split(' ', ',', '.')
     .Where(x => !string.IsNullOrWhiteSpace(x))
     .ToHashSet();
     
     int matched = words1.Intersect(words2).Count();
     
     int maxWords = Math.Max(words1.Count, words2.Count);
     
     return (double)matched / maxWords * 100;
    }
    

    Thanks.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.