From: Yohanes Santoso Date: 2005-01-26T15:38:21+09:00 Subject: Re: String.str_replace ???? Eko Budi Setiyo writes: > But I already manage to make String.str_replace (case sensitive) and > String.str_ireplace (incase sensitive) pass all my unit test > I already check there is not same function yet build in Ruby object But there is: String#gsub() class String def str_replace(what, with) re = Regexp.new(Regexp.quote(what)) self.gsub(re) {with} end def str_ireplace(what, with) re = Regexp.new(Regexp.quote(what), Regexp::IGNORECASE) self.gsub(re) {with} end end raise "Failed" if "aaaaaaaa0aaaaaa3aaaaaaa".str_ireplace("AA", "") != "03a" raise "Failed" if "aaaaaaaa0aaaaaa3aaaaaaa".str_ireplace("A", "") != "03" YS.