2

I have a javascript string containing 3 zero-width space.

https://jsfiddle.net/cmedina/pe1jup8a/

4 returns when var.length use.

enter image description here

My question is how can I delete the zero-width space to be able to compare

"." === "."

and return true.

in JavaScript remove ZERO WIDTH SPACE (unicode 8203) from string

I found a solution, but is not valid for this, I try

 var a =".";
 var b = a.replace(/\u200B/g,'');
 var c = a.replace(/\u200B/g,'');
 console.log(a.length);
 console.log(b);
 console.log(c.length);

but always returns 4 characters.

https://jsfiddle.net/cmedina/kxk2raaL/

Community
  • 1
  • 1
CMedina
  • 4,034
  • 3
  • 24
  • 39
  • 1
    .trim() doesn't seem to handle it, so you can always fake up your own and explicitly add zero-width spaces to the "to-be-removed" chars list, as per the prototype shown here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim – Marc B Feb 19 '16 at 15:00

0 Answers0