quote:
Originally posted by Mnjul
Maybe this will work..
jscript code:
function startsWithToken(orig, str)
{
return orig.indexOf(str)===0;
}
function endsWithToken(orig, str)
{
return orig.lastIndexOf(str)===(orig.length-str.length);
}
I'm assuming str won't be longer than orig. If str's length is exactly one char more than orig's length, then orig.length-str.length returns -1 which evaluates the expression to true.
Fixed by using:
js code:
return (orig.lastIndexOf(str)===orig.length-str.length) && (orig.length>=str.length);
----------------------
For that triple '=', those are
identity operators (opposed to a double '=' which is a
equality operator). In almost all cases it is better to use identity operators instead of equality operators, unless there is a specific reason you need equality instead of identity.
see
CookieRevised's reply to Script about lock messenger.
or look it up in the
Windows Script Documentation > Index > Comparison operators > JScript5.6