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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -