[Tutor] formatting strings

Sean 'Shaleh' Perry shalehperry@attbi.com
Mon, 03 Jun 2002 09:42:44 -0700 (PDT)


On 03-Jun-2002 Chris Avery wrote:
> Hi.  I need to format a string so that the newline is indented.  For example,
> it would need to look like this:
> 
>       * this is a line that is really long and should change to a newline
abou        t
> here and it is the same line still and I am a turkey etc. etc.
> 
> and not like this:
>       * this is a line that is really long and should change to a newline
about
> here and it is the same line still and I am a turkey etc. etc. 
> 
> Thanks for your help
> 

so let's stop and think about this one for a moment.  How does say your text
editor handle line wrapping?  It keeps a maximum line width variable and checks
the line against it.  When the length is reached it inserts a newline and the
rest of the line becomes a new line.

Indentation is simply extra whitespace (a tab, 4 chars, something).  So it
would go something like this:

....
handle line things
....
if (len(line) > max_line_length):
  line = (line before max_line_length) + '\n'
  next_line = (indent) + (remainder)
....
....