LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-05-2007, 11:32 PM   #1
Mithrilhall
Member
 
Registered: Feb 2002
Location: Massachusetts
Distribution: Debian (Lenny)
Posts: 286

Rep: Reputation: 30
Question Python - Removing first x characters


Is there any easy way to remove the first x characters of a string? I'm looking for the equivalent of substr if possible.
 
Old 01-06-2007, 12:33 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
To process a string in Python, you use indexes

eg

Code:
s = "astring"
print s[4:] #remove first 4 characters.
pls read the tutorial at http://docs.python.org/tut/
to get better understanding...
 
Old 01-06-2007, 12:37 AM   #3
jonwatson
Member
 
Registered: Jun 2004
Location: Nova Scotia, Canada!
Distribution: Ubuntu
Posts: 170

Rep: Reputation: 30
While I'm not sure exactly what you're doing, I feel compelled to mention awk. If you're parsing a text file then awk may well be more suitable. There's a TON of functionality in awk that isn't really documented all that well in the awk man page. A good primer is here:

http://sparky.rice.edu/~hartigan/awk.html

HTH

Jon
 
Old 01-16-2007, 09:52 AM   #4
billiejoex
Member
 
Registered: Oct 2005
Posts: 31

Rep: Reputation: 15
>>> s = '0123456789'
>>> s[1:]
'123456789'
>>> s = s[1:]
>>> s
'123456789'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify the names of files and replace characters with other characters or symb peter88 Linux - General 2 12-10-2006 03:05 AM
Removing a colon and all characters before it, in a python list tangle Programming 4 09-12-2006 09:48 PM
Removing Characters when outputting to a script thedarkdestroyer Linux - Newbie 3 03-21-2006 03:13 PM


All times are GMT -5. The time now is 05:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration