From: Logan Capaldo Date: 2007-08-14T19:26:43+09:00 Subject: Re: Exchanging the extension in a filename ------=_Part_35045_16307494.1187087201405 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/14/07, Ronald Fischer wrote: > > I have a string representing the name of a java file. I would > like to get a new string, where the extension .java has been > replaced by .class. > > My approach was to use String#sub: > > filename="abc/x.java" > filename.sub(/java$/,'class') > > This works fine, but I wonder whether there isn't a more > elegant way to do it. sub is pretty elegant. If you wanted you could do it like File.join(File.dirname(filename), File.basename(filename, ".java") + ".class") Ronald > -- > Ronald Fischer > Phone: +49-89-452133-162 > > ------=_Part_35045_16307494.1187087201405--