美好的一天。
我需要检查字符串是否更改了一个或多个字符。例如:
var string = "Orange"; //default
var string2 = "Orange"; // Equals
var string3 = "Oronge"; // orOnge just 1
var string4 = "Orongo"; // orOngO 2 or more.
verificar(string, string2); // return 2
verificar(string, string3); // return 0
verificar(string, string4); // return 1
function verificar(a, b){
//Here I need the code which returns 0 if only one character is modified or 1 if it has been modified two or more characters, or 2 in case you have not changed anything.
}
有什么建议吗?
您好!
最佳答案
您正在寻找的是 Levenshtein Distance .
In information theory and computer science, the Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one word into the other.
通过 Google 搜索可以轻松找到许多实现,例如 this one .
关于javascript - 检查单个字符是否更改为字符串或者是否有多个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34361544/