470,849 Members | 1,515 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

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

Please tell this newbie how to remove n characters from the right end of a
string.

Thanks, Robert
Jul 18 '05 #1
3 71226
"Robert" <no****@nospam.net> wrote in message
news:GU******************@fe2.texas.rr.com...
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
Jul 18 '05 #2

"Paul McGuire" <pt***@austin.rr._bogus_.com> wrote in message
news:yd*******************@fe2.texas.rr.com...
"Robert" <no****@nospam.net> wrote in message
news:GU******************@fe2.texas.rr.com...
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
Jul 18 '05 #3
On Sat, 26 Jun 2004 23:45:42 GMT, Robert <no****@nospam.net> 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
72°39'71"W 42°19'42"N

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by mr h q | last post: by
3 posts views Thread by o_swas | last post: by
3 posts views Thread by Brian Shannon | last post: by
3 posts views Thread by ad | last post: by
7 posts views Thread by Matt | last post: by
6 posts views Thread by garyusenet | last post: by
2 posts views Thread by =?Utf-8?B?YmJkb2J1ZGR5?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.