Python Forum
Split string into 160-character chunks while adding text to each part
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split string into 160-character chunks while adding text to each part
#8
This is the code I used.
message = 'As a reminder, you have an appointment with Dr. Smith tomorrow at 3:30 pm. If you are unable to make this appointment, please call our customer service line at least 1 hour before your scheduled appointment time.'

count = 0
num = 0
output = ('', '', '', '', '', '', '', '', '')

for i in message:
    count += 1
    if count < 161:
        outputStr = output[num] + i
        ouput[num] = outputStr
    else:
        num += 1
        outputStr = output[num] + i
        output[num] = outputStr
        count = 0

messsageNum = 0

for x in output:
    if x != '':
        messageNum += 1
        print(f'message number {messageNum} is {x} and has a length of {len(x) character}')
        print('')
Reply


Messages In This Thread
RE: Split string into 160-character chunks while adding text to each part - by SheeppOSU - May-08-2019, 01:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading a text until matched string and print it as a single line cananb 1 2,068 Nov-29-2020, 01:38 PM
Last Post: DPaul
  Replacing a few characters of a specified character but not all of them from a string fatherted99 7 3,315 Aug-13-2020, 09:08 AM
Last Post: fatherted99
  Appending to a text string syno7878 10 4,327 May-03-2020, 10:05 AM
Last Post: snippsat
  Using an integer to manipulate a string/text variable rexyboy2121 1 1,807 Apr-22-2020, 01:37 AM
Last Post: michael1789
  Adding string numbers, while loop and exit without input. Jose 11 7,628 Apr-15-2020, 08:34 AM
Last Post: Jose
  Trying to extract Only the capitol letters from a string of text Jaethan 2 2,216 Feb-27-2020, 11:19 PM
Last Post: Marbelous
  How to change part of the value string in Python Dictionary? sbabu 11 4,017 Feb-12-2020, 02:25 AM
Last Post: sbabu
  Tab character in a string prints 8 spaces hecresper 6 20,794 Aug-27-2019, 02:38 PM
Last Post: snippsat
  Split String lekuru01 6 3,595 Mar-19-2019, 10:42 AM
Last Post: lekuru01
  Finding and storing all string with character A at middle position Pippi 2 2,731 Jan-20-2019, 08:23 AM
Last Post: Pippi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020