Unprintable characters

S

Stuart Clarke

Hi all,

Rather difficult problem I have I think.

I am processing large amounts of data and at the end of processing I
wish to remove all unprintable characters from the resulting file.

At the moment I have to load the file up into a good text application
and run a find and replace find the following phrase

find: [^[:print:]]
replace:

I then select regular expression of the find and replace and it goes off
and looks for all unprintable characters and replaced them with nothing.

Ideally I would like to do this in Ruby, something like

data.gsub([^[:print:]], "")

Obviously it is far more complex that this and I am looking for input.

Thanks in advance
 
P

pharrington

Hi all,

Rather difficult problem I have I think.

I am processing large amounts of data and at the end of processing I
wish to remove all unprintable characters from the resulting file.

At the moment I have to load the file up into a good text application
and run a find and replace find the following phrase

find: [^[:print:]]
replace:

I then select regular expression of the find and replace and it goes off
and looks for all unprintable characters and replaced them with nothing.

Ideally I would like to do this in Ruby, something like

data.gsub([^[:print:]], "")

Obviously it is far more complex that this and I am looking for input.

Thanks in advance

is it?

this seems to work without problem for me:

data = File.read("some/crazy/mp3")
data.gsub(/[^[:print:]]/, "")

Ruby 1.9 needs force_encoding("binary"), but basically the same deal.

I assume I'm missing something obvious :\
 

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

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top