Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to trim n characters from right end of a string?

Reply
Thread Tools

How to trim n characters from right end of a string?

 
 
Robert
Guest
Posts: n/a
 
      06-26-2004
Please tell this newbie how to remove n characters from the right end of a
string.

Thanks, Robert


 
Reply With Quote
 
 
 
 
Paul Bissex
Guest
Posts: n/a
 
      06-27-2004
On Sat, 26 Jun 2004 23:45:42 GMT, Robert <(E-Mail Removed)> wrote:
>
> Please tell this newbie how to remove n characters from the right end of a
> string.


What Tony said, plus this:

>>> s = "chopme"
>>> n = 2
>>> s = s[:-n]
>>> print s

chop



--
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
7239'71"W 4219'42"N

 
Reply With Quote
 
 
 
 
Paul McGuire
Guest
Posts: n/a
 
      06-27-2004
"Robert" <(E-Mail Removed)> wrote in message
news:GUnDc.13670$(E-Mail Removed)...
> Please tell this newbie how to remove n characters from the right end of a
> string.
>
> Thanks, Robert
>
>

At the Python '>>>' prompt:

>>> a = "This is a string."
>>> print a[:-5]

This is a st


 
Reply With Quote
 
Robert
Guest
Posts: n/a
 
      06-27-2004

"Paul McGuire" <(E-Mail Removed)._bogus_.com> wrote in message
news:ydoDc.13674$(E-Mail Removed)...
> "Robert" <(E-Mail Removed)> wrote in message
> news:GUnDc.13670$(E-Mail Removed)...
> > Please tell this newbie how to remove n characters from the right end of

a
> > string.
> >
> > Thanks, Robert
> >
> >

> At the Python '>>>' prompt:
>
> >>> a = "This is a string."
> >>> print a[:-5]

> This is a st
>
>


Got it! Thanks Tony and Paul!

Robert


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 26 02-26-2007 05:06 PM
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 6 12-25-2006 08:47 PM
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 0 10-25-2006 11:00 PM
FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? FAQ server Javascript 0 08-28-2006 11:00 PM



Advertisments