Splitting a message up into two

Reply

Join Date: Nov 2008
Posts: 58
Reputation: adam291086 is an unknown quantity at this point 
Solved Threads: 0
adam291086 adam291086 is offline Offline
Junior Poster in Training

Splitting a message up into two

 
0
  #1
Feb 25th, 2009
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

  1. Message = "sdkfhdslkfhdskfhsdlfjsdlk"
  2. print len(Message)


but i am not sure od how to split it.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,605
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: Splitting a message up into two

 
0
  #2
Feb 25th, 2009
  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC