The Levenshtein distance between two strings is a measurement of similarity. The smaller the distance, the more similar two strings are. Our PHP programmer friends have a function to calculate this distance; we deserve one too.
ASP
function levenshtein(byVal first, byVal second)dim distancedim truncateLengthif first = second then' The distance is zero if the strings are identical.distance = 0else' The distance is at least the difference of the lengths of the two strings.distance = abs(len(first) - len(second))' Force the strings to be the same length to prevent overflows.truncateLength = ((len(first) + len(second)) - distance) / 2first = Left(first, truncateLength)second = Left(second, truncateLength)' Compare the corresponding characters in each string.for i = 1 to truncateLengthif Mid(first, i, 1) <> Mid(second, i, 1) thendistance = distance + 1end ifnextend iflevenshtein = distanceend function
No comments:
Post a Comment