473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

trim string

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
Jul 19 '05 #1
8 16755
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

"Christopher Brandsdal" <ch***********@c2i.net> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
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

Jul 19 '05 #2
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

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #3
Thank's to both of you!
"Evertjan." <ex**************@interxnl.net> skrev i melding
news:Xn********************@194.109.133.29...
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

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jul 19 '05 #4
Why not Right(strData,4)?

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

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
-------------------------------------------------
Jul 19 '05 #5
He wanted to remove the file extension, not remove the filename.

Ray at work

"dlbjr" <do******@do.you> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...
Why not Right(strData,4)?

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

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

Jul 19 '05 #6
"dlbjr" <do******@do.you> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...
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.
Jul 19 '05 #7
"Christopher Brandsdal" wrote:

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().jo in("")

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.
Jul 19 '05 #8
okey doke

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

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
-------------------------------------------------
Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: DrBob | last post by:
gcc 3.3 MAC OS X. I have a string that has trailing spaces in it that I want removed. So i have a variable: string x("abcd "); x.trim() isn't an implemented method. Is there a method I...
3
by: Jon Kelling | last post by:
for all your javascript trimming needs... function trim(inputString) { if (typeof inputString != "string") return inputString; return inputString //clear leading spaces and empty lines...
22
by: Terry Olsen | last post by:
I have an app that makes decisions based on string content. I need to make sure that a string does not contain only spaces or newlines. I am using the syntax 'Trim(String)" and it works fine. I...
121
by: swengineer001 | last post by:
Just looking for a few eyes on this code other than my own. void TrimCString(char *str) { // Trim whitespace from beginning: size_t i = 0; size_t j; while(isspace(str)) {
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.