943,604 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 293
  • Python RSS
Feb 25th, 2009
0

Splitting a message up into two

Expand Post »
I am trying to spilt a message in two, if the number of characters is greater that 600, so that each message has no more than 600 characters.

How can i do this
i know how to get the message length

Python Syntax (Toggle Plain Text)
  1. Message = "sdkfhdslkfhdskfhsdlfjsdlk"
  2. print len(Message)


but i am not sure od how to split it.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
adam291086 is offline Offline
61 posts
since Nov 2008
Feb 25th, 2009
0

Re: Splitting a message up into two

python Syntax (Toggle Plain Text)
  1. pieces = []
  2. while len(message) > 600:
  3. pieces.append(message[:600]) # slice from the start up to (but not including) the 600th character.
  4. message= message[600:] #slice from the 600th character to the end.
  5. pieces.append(message)

That should split the string up into pieces that are 600 characters long or less. The pieces are stored in the list 'pieces'.
Last edited by scru; Feb 25th, 2009 at 1:18 pm.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: pygtk: Disable buttons, Comboboxes, checkboxes...
Next Thread in Python Forum Timeline: Printing In Python





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC