Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# string "likeness" comparison test

Tags:

string

c#

testing

Are there any libraries out there that make it easy to compare the "likeness" of 2 strings in C#? What I am thinking is if you have the strings,

"This is a test" // 100%
"THIS IS A TEST" // 95%
"    This is a test" // 98%
"This is" // 60%
"Foobar" // 0%
"this test is a" // 70%

etc. They would each be given a score compared to a base string.

like image 552
mike Avatar asked Oct 14 '22 21:10

mike


1 Answers

Have a look at Levenstein.

The Levenshtein distance is the difference between two strings. I use it in a web crawler application to compare the new and old versions of a web page. If it has changed enough, I update it in my database.

CodeProject has an implementation of this at http://www.codeproject.com/KB/recipes/Levenshtein.aspx.

like image 130
Pieter van Ginkel Avatar answered Oct 18 '22 03:10

Pieter van Ginkel