[Tutor] String question.
Carlos Benevides
carlos at carlosbenevides.com
Thu Apr 13 01:45:47 CEST 2006
All,
I have a problem/question I'd like to pose to you guys on how best to
accomplish the following. I have a string that will vary in size, what
I would like to do is split into n size chunks. I am also not sure how
best to represent the chunks. For example, say I have a len(s) = 200
chars. I'd like to get one chunk with 160 of those chars and the
remaining 40 in a second. Likewise, if I have a len(s) = 350, I'd like
two chunks of 160 and a 3rd with the remainder.
I don't know what it would best way to accomplish this. I have the idea
of converting the string to a list of chars loop through it until size
is met, create a new string with s=s[:160], then start again, and so
on. Is this the only way to accomplish this? Or is there a more
elegant/clever way?
Thank you :)
More information about the Tutor
mailing list