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:
Flippy
Junior Member
**


Posts: 29
35 / Male / Flag
Joined: Jun 2009
O.P. startsWith() and endsWith()
Hey,

I'm looking for a function that will tell me if a string starts or ends with a certain string. In any language I've worked in so far you had the StartsWith() and EndsWith() functions, but they don't seem to work in jscript.

I've looked on google, but I could only find examples for Javascript, for example this:
http://www.tek-tips.com/faqs.cfm?fid=6620

So I decided just to use that in jscript, but it won't work.


The first try, I made it into this:
(Note that I didn't try to use that 'prototyping' thing, don't need that):
jscript code:
function startsWithToken(orig, str)
{
    return (orig.match("^"+str)==str)
}
function endsWithToken(orig, str)
{
    return (orig.match(str+"$")==str)
}
But it didn't work. They are returning false while they should be true.

I figured maybe the regex works differently in jscript, and I was stuck there... I didn't know how to convert it to jscript properly.

So I decided to just make it work for my purpose only, which is to see if the orig string starts or ends with the string "$$".

So I made it into this:
jscript code:
function startsWithToken(orig)
{
    return (orig.match(/^\$\$/) == "$$")
}
function endsWithToken(orig)
{
    return (orig.match(/^\$\$$/) == "$$")
}

Now, the startsWith function works fine, but the endsWith method does not...

I suppose my regex is faulty, especially with the many $ signs lol... The last $ sign appears to mean something like "at the end" (I guess, I'm really rusty at regex), but I also need it to check the string for actual $ characters...

Can anyone help me out? This shouldn't be too hard, but unfortunately jscript is a little... well :$ let's just say I don't like it too much hehe.
06-17-2009 04:59 PM
Profile E-Mail 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