RE: easy way to remove nonprintable chars from string

Discussion in 'Python' started by sismex01@hebmex.com, Jul 24, 2003.

  1. Guest

    > From: Isaac Raway [mailto:]
    > 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.
     
    , Jul 24, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Don Hiatt
    Replies:
    3
    Views:
    1,645
    Terry Reedy
    Jul 24, 2003
  2. Kosio

    Floats to chars and chars to floats

    Kosio, Sep 16, 2005, in forum: C Programming
    Replies:
    44
    Views:
    1,330
    Tim Rentsch
    Sep 23, 2005
  3. Hongyu
    Replies:
    9
    Views:
    951
    James Kanze
    Aug 8, 2008
  4. M.Posseth

    receiving ??? chars instead of "special" chars

    M.Posseth, Nov 15, 2004, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    272
    Dan Rogers
    Nov 16, 2004
  5. Replies:
    1
    Views:
    192
    Robert Klemme
    May 31, 2006
Loading...

Share This Page