Javascript - string comparison failing -
i comparing 2 strings
if (sphtext == sphspantext) { //"sample " === "sample " comparison fails return true; }
the comparison fails if both strings have space @ end. sphtext read xml file , sphspantext html page. if there no spaces works fine. wondering due encoding issues. if use trim works.
how can make work?
your string must have different whitespace character such normal space or non-breaking space.
you can replace whitespace regular space :
sphspantext.replace(/\s/g, ' ');
Comments
Post a Comment