-1

Why is this returning false all the time?

var a = new String("17-0069,,Alex Libengood,Travel from - Meadors Office - to - 201 Hildebrand Dr, Bonneau SC,Site inspection,,0.55,/mile,0,miles,,1,17-0069><><Alex Libengood><Travel from - Meadors Office - to - 201 Hildebrand Dr, Bonneau SC><Site inspection><0.55><1,Mileage").trim();
var b = new String("17-0069,,Alex Libengood,Travel from - Meadors Office - to - 201 Hildebrand Dr, Bonneau SC,Site Inspection,,0.55,/mile,0,miles,,1,17-0069><><Alex Libengood><Travel from - Meadors Office - to - 201 Hildebrand Dr, Bonneau SC><Site Inspection><0.55><1,Mileage").trim();
if (a === b){
   return true;
} else {
   return false;
}

It's the same string!

I've seen other questions answered by using the trim() method, but it's not working for me. It's like there are hidden characters somewhere in the strings that I can't see. But when I test the lengths, they are both 255 characters long.

Alex Libengood
  • 510
  • 1
  • 4
  • 11

1 Answers1

2

It's the same string!

No, it's not. Look closely:

"17-0069,,Alex Libengood,Travel from - Meadors Office - to - 201 Hildebrand Dr, Bonneau SC,Site inspection,,0.55,/mile,0,miles,,1,17-0069><><Alex Libengood><Travel from - Meadors Office - to - 201 Hildebrand Dr, Bonneau SC><Site inspection><0.55><1,Mileage"
"17-0069,,Alex Libengood,Travel from - Meadors Office - to - 201 Hildebrand Dr, Bonneau SC,Site Inspection,,0.55,/mile,0,miles,,1,17-0069><><Alex Libengood><Travel from - Meadors Office - to - 201 Hildebrand Dr, Bonneau SC><Site Inspection><0.55><1,Mileage"
                                                                                                ^                                                                                                                                    ^

Those are not hidden characters, they're simply different cases of i/I. Found with

for (let i=0; i<255; i++) if (a[i] != b[i]) console.log(i, a[i], b[i])
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Well, that's embarrassing :0 I thought I checked for that like 15 times, and still didn't see it. That code snippet is a good idea to check for it though. Thanks @Bergi! – Alex Libengood Jun 28 '19 at 12:57