Сравните две строки в js и найдите разницу
how to compare two strings purely, and provide specific result such as highlight extra word, wrong word & skip word in 2nd string. for eg. var x = "This is the first original string in javascript language." </br> var y = "This is not the first org string in language." diff = wrong word ="org"<br> Extra word ="not"<br> skip word ="javascript" <pre> <script lang="Javascript"> //here is slice of my code but in some case my program fails var x = "here is some value of string"; var y = "here is the some val string"; var k=0; var SkipWrd=""; for(var i=0; i<y.length;i++){ var sktmp=""; var swtmp=0; for(var j=0; j<=2;j++) { if(x[k]!="undefined"){ if(y[i]==x[k+j]){ SkipWrd+=sktmp; skip+=swtmp; H_wrd += typ_wrd[i]+" "; org_para+= sktmp+x[k+j]+" "; k+=j+1; break; } else{ sktmp+= "<mark>"+ x[k+j]+" "+ "</mark>"; swtmp++; if(j==2 && y[i]!=x[k+j]){ err++; Err_Wrd+=y[i]+" "; H_wrd += "<span id='H-Err'>" + typ_wrd[i] + "</span> "; org_para+="<span id='O-Err'>" +x[k]+" "+ "</span> "; k++; } } } } }
Что я уже пробовал:
если лишнее слово включено во 2-ю строку, то остальная строка считается неправильным словом.