From: Mark Hubbart Date: 2004-12-02T16:56:53+09:00 Subject: Re: Does Ruby have anything like isprint? Hi, On Thu, 2 Dec 2004 15:17:43 +0900, 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? Not that I know of. But here's a way to get a copy of a string with all non-printable characters stripped out: # get a string with all possible byte values: str = (0..255).map{|b| b.chr}.join # print all printable characters: print str.gsub(/[[:^print:]]+/, "") That gsub there finds all runs of non-printing characters, and replaces them with an empty string (ie, nothing). HTH, Mark