trim string

  • Thread starter Christopher Brandsdal
  • Start date
C

Christopher Brandsdal

How do i cut the last 4 characters in a string?
I know how to cut the 4 first, but i need to cut the last!
I have a image name like testimage.gif and I want to cut away .gif



Thanks
Christopher
 
R

Ray at

If you just want to cut away the last four, use:

TheString = Left(TheString, Len(TheString) - 4)

If you want to get rid of the file extension, here is one of many ways:

TheString = Left(TheString, InStrRev(TheString, ".") - 1)

Ray at work
 
E

Evertjan.

Christopher Brandsdal wrote on 31 jul 2003 in
microsoft.public.inetserver.asp.general:
How do i cut the last 4 characters in a string?
I know how to cut the 4 first, but i need to cut the last!
I have a image name like testimage.gif and I want to cut away .gif

vbscript:

s = left(s,len(s)-4)

jscript:

s = s.substring(0,s.length-4)

not tested
 
C

Christopher Brandsdal

Thank's to both of you!


Evertjan. said:
Christopher Brandsdal wrote on 31 jul 2003 in
microsoft.public.inetserver.asp.general:

vbscript:

s = left(s,len(s)-4)

jscript:

s = s.substring(0,s.length-4)

not tested
 
D

dlbjr

Why not Right(strData,4)?

-------------------------------------------------
d l b j r

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
-------------------------------------------------
 
C

Chris Hohmann

dlbjr said:
Why not Right(strData,4)?

-------------------------------------------------
d l b j r

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
OP wants everything BUT the last four (4) characters.
 
D

Dave Anderson

Christopher Brandsdal said:
How do i cut the last 4 characters in a string?
I know how to cut the 4 first, but i need to cut
the last! I have a image name like testimage.gif
and I want to cut away .gif

Easy way:
filename.replace(/\.[^.]*?$/,"")

Silly way:
filename.split("").reverse().slice(4).reverse().join("")

Both JScript. The regular expression will properly handle extensions of
variable length (jpg or jpeg), and will not totally hose such filenames as
"My.oddly.named.filename.gif".



--
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

dlbjr

okey doke

-------------------------------------------------
d l b j r

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
-------------------------------------------------
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top