From: William James Date: 2007-08-15T02:55:01+09:00 Subject: Re: Exchanging the extension in a filename On Aug 14, 5:05 am, "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. > > Ronald > -- > Ronald Fischer > Phone: +49-89-452133-162 filename = "abc/x.java" ==>"abc/x.java" filename[ /java$/ ] = "class" ==>"class" filename ==>"abc/x.class"