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.