easy way to remove nonprintable chars from string
Bjorn Pettersen
BPettersen at NAREX.com
Thu Jul 24 16:41:02 EDT 2003
> From: Isaac Raway [mailto:isaac at blueapples.org]
> >Don Hiatt wrote:
>
> >Greetings,
> >
> >Is there an easy way to remove multiple non-printable
> >(e.g. "not strings.printable") from a string? Perhaps
> >something like foo.replace(list_of_nonprintables, '')
> >if it only existed? :-)
>
> This seems to work. Not sure how fast it'd be, though.
>
> def stripNoPrint(str):
> results = ""
> for char in str:
> if string.printable.find(char):
> results += char
> return results
try it on the string '0 plus 1 equals 1' :-)
-- bjorn
More information about the Python-list
mailing list