473,563 Members | 2,681 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 16775
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
17718
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
7011
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
9719
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...
121
5027
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
7659
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...
0
7580
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...
0
8103
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...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6244
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...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
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
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.