From: Robert Klemme Date: 2004-12-02T19:52:42+09:00 Subject: Re: Does Ruby have anything like isprint? "Dave Burt" schrieb im Newsbeitrag news:LJzrd.55898$K7.47722@news-server.bigpond.net.au... > "Martin Kahlert" wrote... > > Hi! > > > > I want to print out the 'printable' characters from a binary > > data stream. > > Is there anything like C's isprint() function in Ruby? > > > > Thanks, > > Martin. > > You can use the POSIX regular expression 'metacharacter' [:print:] to match > a printing character. > > def isprint(c) > /[[:print:]]/ === c.chr > end > > Or you can .gsub(/[^[:print:]]/, '') on a string, etc. I prefer to use scan as this is likely more memory efficient (no copy of the whole thing needed): binary_string.scan(/[[:print:]]+/) { |s| print s } Kind regards robert