Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: easy way to remove nonprintable chars from string

Reply
Thread Tools

RE: easy way to remove nonprintable chars from string

 
 
sismex01@hebmex.com
Guest
Posts: n/a
 
      07-24-2003
> From: Isaac Raway [(E-Mail Removed)]
> Sent: Jueves, 24 de Julio de 2003 03:04 p.m.
>
> 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
>


And to make this thread end quickly, the functional version
of the above would be like:

def StripNoPrint(S):
from string import printable
return "".join(filter(lambda ch:ch in printable, S))

And converted to use list comprehensions:

def StripNoPrint(S):
from string import printable
return "".join([ ch for ch in S if ch in printable ])

HTH!!!

-gustavo
Advertencia:La informacion contenida en este mensaje es confidencial y
restringida, por lo tanto esta destinada unicamente para el uso de la
persona arriba indicada, se le notifica que esta prohibida la difusion de
este mensaje. Si ha recibido este mensaje por error, o si hay problemas en
la transmision, favor de comunicarse con el remitente. Gracias.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to truncate char string fromt beginning and replace chars instring by other chars in C or C++? Hongyu C++ 9 08-08-2008 12:18 PM
Easy way to replace all non-alpha numeric chars in a string? deja@homerlex.mailshell.com Ruby 1 05-31-2006 04:18 PM
Floats to chars and chars to floats Kosio C Programming 44 09-23-2005 09:49 AM
receiving ??? chars instead of "special" chars M.Posseth ASP .Net Web Services 3 11-16-2004 07:00 PM
easy way to remove nonprintable chars from string Don Hiatt Python 3 07-24-2003 08:47 PM



Advertisments