Reversible replacement of whitespace characters with visible characters

M

Micah

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
 
J

James Stroud

Micah said:
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/
 
M

Micah

James said:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top