473,707 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 16799
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(TheStr ing, ".") - 1)

Ray at work

"Christophe r Brandsdal" <ch***********@ c2i.net> wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
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.publi c.inetserver.as p.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******** ************@19 4.109.133.29...
Christopher Brandsdal wrote on 31 jul 2003 in
microsoft.publi c.inetserver.as p.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.yo u> wrote in message
news:OA******** ******@tk2msftn gp13.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.yo u> wrote in message
news:OA******** ******@tk2msftn gp13.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
"Christophe r 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.replac e(/\.[^.]*?$/,"")

Silly way:
filename.split( "").reverse().s lice(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.
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
17729
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 don't know about? What do I do to extent the string class such that there is a method to
3
7018
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 .replace(/^(\s|\n|\r)*((.|\n|\r)*?)(\s|\n|\r)*$/g,"$2") //take consecutive spaces down to one .replace(/(\s(?!(\n|\r))(?=\s))+/g,"")
22
9738
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 thought I'd change it to the VB ..NET method "String.Trim" but that throws an object exception. Which brings the question: is it compliant to use Trim(String), or is it more within etiquette to use If Not String Is Nothing Then String.Trim?
121
5110
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
8787
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9289
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9158
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7921
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4712
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3151
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.