D'ish similar_text?
Dgame
r.schuett.1987 at gmail.com
Thu May 10 20:32:11 UTC 2018
On Thursday, 10 May 2018 at 20:13:49 UTC, Vladimir Panteleev
wrote:
> On Thursday, 10 May 2018 at 20:08:04 UTC, Dgame wrote:
>> void similar_text_similar_str(char* txt1, size_t len1, char*
>
> That looks like an implementation of Levenshtein distance. We
> have one in Phobos:
>
> https://dlang.org/library/std/algorithm/comparison/levenshtein_distance.html
Oh, that could to work, thank you. I've just tested it quickly,
but that code seems to produce the same results:
----
size_t similar_text2(in string s1, in string s2, out double
percent) {
import std.algorithm: levenshteinDistance;
immutable size_t distance = s1.levenshteinDistance(s2);
immutable size_t len = s1.length + s2.length;
percent = (len - distance) * 100.0 / len;
return distance;
}
----
More information about the Digitalmars-d-learn
mailing list