Reversible replacement of whitespace characters with visible characters

Discussion in 'Python' started by Micah, Jun 2, 2006.

  1. Micah

    Micah Guest

    Hi,

    I'm looking for a tool to do the following 2 things:

    1) Given a string (ie. file, std input, whatever), replace all
    whitespace characters with visible characters (like their Unicode value
    or something). The end result will be one long unbroken line

    2) Given a string altered as in step 1, "decode" it back to the
    original string.

    Note: The original string (it will usually be source files) might
    already contain Unicode values, and these must remain and not be
    altered in step 2.

    Note 2: I'm working in a Windows XP environment, but I have access to
    cygwin if that makes a difference.

    Can anyone think of a tool that already does this? I could probably
    whip something up, but if there's already something that does it I'd
    rather just use it.

    Micah
    Micah, Jun 2, 2006
    #1
    1. Advertising

  2. Micah

    James Stroud Guest

    Re: Reversible replacement of whitespace characters with visiblecharacters

    Micah wrote:
    > Hi,
    >
    > I'm looking for a tool to do the following 2 things:
    >
    > 1) Given a string (ie. file, std input, whatever), replace all
    > whitespace characters with visible characters (like their Unicode value
    > or something). The end result will be one long unbroken line
    >
    > 2) Given a string altered as in step 1, "decode" it back to the
    > original string.
    >
    > Note: The original string (it will usually be source files) might
    > already contain Unicode values, and these must remain and not be
    > altered in step 2.
    >
    > Note 2: I'm working in a Windows XP environment, but I have access to
    > cygwin if that makes a difference.
    >
    > Can anyone think of a tool that already does this? I could probably
    > whip something up, but if there's already something that does it I'd
    > rather just use it.
    >
    > Micah
    >


    Try urllib.

    py> import urllib
    py> astr = 'faf\tfasf dsf\ndsfds dsf dsaf \t\r'
    py> urllib.quote(astr)
    'faf%09fasf%20dsf%0Adsfds%20dsf%20dsaf%20%09%0D'
    py> print astr
    faf fasf dsf
    dsfds dsf dsaf

    James

    --
    James Stroud
    UCLA-DOE Institute for Genomics and Proteomics
    Box 951570
    Los Angeles, CA 90095

    http://www.jamesstroud.com/
    James Stroud, Jun 2, 2006
    #2
    1. Advertising

  3. Micah

    Micah Guest

    James Stroud wrote:
    > Micah wrote:
    > > Hi,
    > >
    > > I'm looking for a tool to do the following 2 things:
    > >
    > > 1) Given a string (ie. file, std input, whatever), replace all
    > > whitespace characters with visible characters (like their Unicode value
    > > or something). The end result will be one long unbroken line
    > >
    > > 2) Given a string altered as in step 1, "decode" it back to the
    > > original string.
    > >
    > > Note: The original string (it will usually be source files) might
    > > already contain Unicode values, and these must remain and not be
    > > altered in step 2.
    > >
    > > Note 2: I'm working in a Windows XP environment, but I have access to
    > > cygwin if that makes a difference.
    > >
    > > Can anyone think of a tool that already does this? I could probably
    > > whip something up, but if there's already something that does it I'd
    > > rather just use it.
    > >
    > > Micah
    > >

    >
    > Try urllib.
    >
    > py> import urllib
    > py> astr = 'faf\tfasf dsf\ndsfds dsf dsaf \t\r'
    > py> urllib.quote(astr)
    > 'faf%09fasf%20dsf%0Adsfds%20dsf%20dsaf%20%09%0D'
    > py> print astr
    > faf fasf dsf
    > dsfds dsf dsaf
    >
    > James
    >
    > --
    > James Stroud
    > UCLA-DOE Institute for Genomics and Proteomics
    > Box 951570
    > Los Angeles, CA 90095
    >
    > http://www.jamesstroud.com/



    Perfect!! Just what I was looking for!
    Micah, Jun 2, 2006
    #3
    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. Replies:
    15
    Views:
    626
    Ben Bacarisse
    Oct 14, 2007
  2. Reversible random generator ?

    , Oct 9, 2007, in forum: C Programming
    Replies:
    19
    Views:
    727
    Ben Bacarisse
    Oct 14, 2007
  3. Patrick Sabin

    Reversible Debugging

    Patrick Sabin, Jul 3, 2009, in forum: Python
    Replies:
    0
    Views:
    225
    Patrick Sabin
    Jul 3, 2009
  4. Patrick Sabin

    Re: Reversible Debugging

    Patrick Sabin, Jul 4, 2009, in forum: Python
    Replies:
    5
    Views:
    283
    Vilya Harvey
    Jul 4, 2009
  5. Eric Pearson

    recovering password stored with reversible encryption?

    Eric Pearson, Jun 2, 2006, in forum: ASP .Net Security
    Replies:
    3
    Views:
    334
    Eric Pearson
    Jun 7, 2006
Loading...

Share This Page