Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

remove nonprintable characters (See related posts)

def printable(str)
  return "" unless str
  eval(str.strip.dump.gsub(/\\[0-9]{3}/,''))
end

Comments on this post

threedaymonk posts on Sep 04, 2006 at 13:59
I don't want to offend the original poster too much, but this is a really bad solution to the problem.

Assuming that you want only printable ASCII characters, here is a better, more efficient, less convoluted way:

def printable(str)
  str && str.gsub(/[^\x20-\x7e]+/, '')
end
kelyar posts on Sep 08, 2006 at 12:42
thanks

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts