Here's how we normalize whitespace in multiline blocks of text. Perhaps
you can adapt this routine to your needs? Watch for line wrap.
# clean up duplicate whitespace, leading/trailing whitespace, triple
CRLF's
def fixwhitespace( text ):
output = []
lastLine = ''
#
oyster wrote:
I have some strings, and I want to write them into a text files, one
string one line
but there is a requirement: every line has a max length of a certain
number ...
If you are doing this to fill and justify text, I seem to remember
a research result stating that filled text (with
here is what I get
[code]
import re
reSplitObj=re.compile('([ \t]*)|([^ \t]*)')
def evenReplace(aStr, length):
aStr=aStr.rstrip()
tmp=reSplitObj.split(aStr)
tmp=[i for i in tmp if i not in ['', None]]
lenStr=[[0, len(i)][i.strip()!=''] for i in tmp]
lenSpc=[[0, len(i)][i.strip()
On Tue, 2 Jun 2009 19:10:18 +0800
oyster wrote:
> I have some strings, and I want to write them into a text files, one
> string one line
> but there is a requirement: every line has a max length of a certain
> number(for example, 10), so I have to replace extra SPACE*3 with
> SPACE*2, at the same
On Jun 2, 12:10 pm, oyster wrote:
> I have some strings, and I want to write them into a text files, one
> string one line
> but there is a requirement: every line has a max length of a certain
> number(for example, 10), so I have to replace extra SPACE*3 with
> SPACE*2, at the same time, I want t
I have some strings, and I want to write them into a text files, one
string one line
but there is a requirement: every line has a max length of a certain
number(for example, 10), so I have to replace extra SPACE*3 with
SPACE*2, at the same time, I want to make the string looks good, so,
for "I am12