cut from string using JScript

  • Thread starter Christopher Brandsdal
  • Start date
C

Christopher Brandsdal

I have this string:

/sites/binaer/demo/fil/Winnie-the-Pooh 1024x768.jpg

If I wanted to cut everything before Winnie-the-Pooh 1024x768.jpg, how would
I do this?

In VBScript I could find the first "/" from the back of the sentence, and
cut everything before that, but I'm not shore how to do this in JScript...

The string I want to end up with is Winnie-the-Pooh 1024x768.jpg

Any idea??
 
C

Christopher Brandsdal

because the rest 550 lines of code in this .asp document is in JScript :)

Think it's best to use JScript in this case
 
E

Evertjan.

Christopher Brandsdal wrote on 03 jun 2004 in
microsoft.public.inetserver.asp.general:
/sites/binaer/demo/fil/Winnie-the-Pooh 1024x768.jpg

If I wanted to cut everything before Winnie-the-Pooh 1024x768.jpg, how
would I do this?

In VBScript I could find the first "/" from the back of the sentence,
and cut everything before that, but I'm not shore how to do this in
JScript...

The string I want to end up with is Winnie-the-Pooh 1024x768.jpg

t="/sites/binaer/demo/fil/Winnie-the-Pooh 1024x768.jpg"

t=t.replace(/.*\//,"")

alert(t)
 
A

Aaron [SQL Server MVP]

Pretty much the same as VBScript.

var s = "/sites/foo/bar.jpg";
Response.Write(s.substring(s.lastIndexOf("/")+1, s.length));

So let me ask, if you're more comfortable with VBScript, why are you
continuing to use JScript... or why don't you have JScript documentation
handy?
 
D

Dave Anderson

Christopher said:
/sites/binaer/demo/fil/Winnie-the-Pooh 1024x768.jpg

If I wanted to cut everything before Winnie-the-Pooh 1024x768.jpg,
how would I do this?

Concisely? This will do:

"/sites/binaer/demo/fil/Winnie-the-Pooh 1024x768.jpg".split("/").pop()
-- or: strFilePathName.split("/").pop()



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
D

David C. Holley

You'll want to see microsoft.public.scripting.jscript

I've posted a reply in that group and you may need them to help you
adapt the VBScript example that I provided.

David H.
www.gatewayorlando.com
 
R

Roland Hall

in message
: /sites/binaer/demo/fil/Winnie-the-Pooh 1024x768.jpg
:
: If I wanted to cut everything before Winnie-the-Pooh 1024x768.jpg, how
would
: I do this?
:
: In VBScript I could find the first "/" from the back of the sentence, and
: cut everything before that, but I'm not shore how to do this in JScript...
:
: The string I want to end up with is Winnie-the-Pooh 1024x768.jpg

Simple enough...

http://kiddanger.com/lab/xname.html

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
C

Christopher Brandsdal

Good question..
Im working on an JScript application which is old, and not made by me...
I have plans to convert it to VBScript, but with 50.000 lines of code, this
takes time...
But I WILL get a JScript documentation :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top