From: Julius Plenz Date: 2004-12-17T03:52:12+09:00 Subject: Re: string to (valid) filename * itsme213 [2004-12-16]: > Don't know much about regexes or File/FileUtils, and am a bit stuck > on what might be quite simple: As I obtain from http://www.rubycentral.com/ref/, there are no such methods defined in File, FileTest or File::Stat. > Is there a simple way to create a valid filename (develop on XP, but > would like the filenames to be valid at least on *nix as well) from > a string that might contain several platform-illegal filename > characters. The conversion could change spaces etc. to '_'. > > e.g. > "Animals: Fox, Wolf, and Bear".to_filename >#=> "animals_fox_wolf_and_bear" You could write your own: class String def to_filename self.to_s.downcase.tr(" ", "_").gsub(/[^\w_\.\-]+/, "") end end Julius -- p"ispp\e[ggk^Zf\23dfRh\16UMNUNZ".unpack("C*").map{|c|@i||=0;c+@i+=1}.pack("C*")