show different letters between 2 words
include skipping special characters
function show_diff(org_text, new_text) {
var i = 0, j = 0, k = 0;
var ret1 = "";
var skip_chrs = Array(" ", ".", "/", "%", "#", "-");new_text = new_text.split(
"");org_text = org_text.split(
"");
for (k = 0; i <= new_text.length; k++) {
if (typeof (new_text[i]) != "string") {i++;
continue;}
if (skip_chrs.exists(new_text[i])) {ret1 +=
"<span>" + new_text[i] + "</span>";i++;
continue;}
if (!org_text[j]) {ret1 +=
"<span style='color:red'>" + new_text[i] + "</span>";i++;
continue;}
if (skip_chrs.exists(org_text[j])) {j++;
continue;}
if (new_text[i] != org_text[j]) {ret1 +=
"<span style='color:red'>" + new_text[i] + "</span>";}
else {ret1 +=
"<span>" + new_text[i] + "</span>";}
i++;
j++;
}
return ret1;}
No comments:
Post a Comment