What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » startsWith() and endsWith()

startsWith() and endsWith()
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: startsWith() and endsWith()
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

This post was edited on 06-17-2009 at 07:31 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-17-2009 07:19 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
startsWith() and endsWith() - by Flippy on 06-17-2009 at 04:59 PM
RE: startsWith() and endsWith() - by Mnjul on 06-17-2009 at 05:28 PM
RE: RE: startsWith() and endsWith() - by Flippy on 06-17-2009 at 06:26 PM
RE: startsWith() and endsWith() - by CookieRevised on 06-17-2009 at 07:19 PM
RE: startsWith() and endsWith() - by Flippy on 06-17-2009 at 07:46 PM
RE: startsWith() and endsWith() - by CookieRevised on 06-17-2009 at 07:52 PM
RE: startsWith() and endsWith() - by markee on 06-18-2009 at 07:46 AM
RE: startsWith() and endsWith() - by CookieRevised on 09-22-2009 at 08:15 AM
RE: startsWith() and endsWith() - by brooooof on 09-27-2009 at 06:43 AM
RE: startsWith() and endsWith() - by jerone on 10-08-2009 at 11:40 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On