Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the closest string match

Tags:

string

c#

find

C# WinApp: Let's say I search for dtg but the items that I am searching in are dvg , dz, dxg ... so I want it to find dvg for me because it is closer to dtg that I was searching for. I know there are some NP-hard algorithms for that but really I do not want to spend a ton of time on this. is there any String methods that does something close to this? or can do it with a few extra liens of code?

like image 697
Bohn Avatar asked Jan 22 '23 03:01

Bohn


1 Answers

You'd need a metric describing the difference between two strings. A common approach is to use the Levenshtein distance, which is quickly implemented using a few lines of C# code (code files are available online).

like image 56
Jim Brissom Avatar answered Jan 31 '23 23:01

Jim Brissom