Is there a reason the JS string will not be equal to itself? (See photo)

Is there a reason why the string will not be equal to itself? I process a large number of lines, and some lines, after all, are not aligned.

Here is an image that shows what I'm talking about.

Example Image

Any ideas?

RESOLVED: There is a carriage return (\ r) attached to the end of one of the lines. I used String.length to view the lengths of each string, and they were different (5 and 6). Then I looked at the string using String.charAt. In Chrome, this showed an empty string (""). However, the empty string was not false. I tried this in FireFox and it showed a carriage return.

+8
javascript string
source share
3 answers

In any language, if one line contains some unreadable characters and the other does not, even if they seem equal to the human.

Try to print their length and print their char -to- char

+10
source share

It is possible that one of the characters is a UTF-8 representation of the ascii equivalent.

Here is the jquery transliteration plugin: http://code.google.com/p/jquery-transliteration-plugin/wiki/Usage

At the end, there may also be a control sequence, as a specification.

+3
source share

You are probably comparing the type of a string value with a string.

See Difference Between Javascript Type String and String Object?

Solution: either use string.valueOf (), or use double equals instead of triple, and let javascript force the String object to a string value.

From my console a = new line ("asdf"); b = "asdf"; a === b; // false a == b; // true a.valueOf () === b.valueOf (); // true

-one
source share

All Articles