I am literally pulling my hair out on this one...
Here's the situation. I have two javascript strings as follows:
dsName = "Test 1"
replacementString = "Test "
I'm trying to see if dsName starts with replacementString, with the following code:
if(dsName.indexOf(replacementString) == 0)
{
// I never get here!
}
indexOf is returning -1!! How is this possible? I can put a breakpoint in Chrome script debugging right before that line and paste "dsName.indexOf(replacementString)" into the console and see that it is indeed returning -1.
Now just to prove I'm not crazy I can from that same breakpoint print out dsName and it does in fact equal "Test 1" and replacementString does equal "Test ". Here is an actual screenshot from the Chrome debugging console:
So as you can see, if I paste in the literal string, it works as expected, but if I use the variable, it doesn't work. I've even tried String(replacementString) and replacementString.toString() to see if maybe it was a type issue, but it does the same thing.
It's like it works if the parameter for indexOf is a literal string, but not if it's a string variable.
Am I going crazy, is there a something stupid I'm missing? Or is this possibly a bug in Chrome?