On 27.04.2007 15:18, Josselin wrote: > On 2007-04-27 11:15:15 +0200, Robert Klemme <shortcutter / googlemail.com> > said: > >> On 27.04.2007 09:29, Josselin wrote: >>> I have a string : str = "/proposal/list/31551" >>> >>> I would like to change the 31551 by another value "9999", but I don't >>> see whicj method I should use ? >>> >>> str.each and block ? or str.rindex('/') and concatenating the new >>> value ? >> >> How about >> >> irb(main):006:0> str = "/proposal/list/31551" >> => "/proposal/list/31551" >> irb(main):007:0> str[%r{\d+$}]="9999" >> => "9999" >> irb(main):008:0> str >> => "/proposal/list/9999" >> >> If it's a file name you could also do >> >> irb(main):012:0> File.join(File.dirname(str), "9999") >> => "/proposal/list/9999" >> >> I estimate there are another 5 million other ways around. :-) >> >> Kind regards >> >> robert > > I forgot to mention my main objective > replacing the term after the > last '/'.. > thanks to all In that case I'd use the File approach or do str[%r{[^/]+$}]="9999" robert