From: mike@... (Mike Stok) Date: 2002-03-23T04:48:17+09:00 Subject: Re: Sub-String In article <9FLm8.16$%g7.14159041@newssvr13.news.prodigy.com>, Sean O'Dell wrote: > What's a good way to grab a sub-string from a string? With string > implementation, I'm used to a substr() or mid() function where you can > specify where you want the sub-string to start and the return is everything > from that point on. > > Here's an example: > > "/home/fred/file.ext".substr(11) => "file.ext" > > What's a good equivalent way to do that in Ruby? "/home/fred/file.ext"[11 .. -1] => "file.ext" "/home/fred/file.ext".slice(11 .. -1) => "file.ext" You need a Range rather than an integer, otherwise you get the character value at that position "/home/fred/file.ext".slice(11) => 102 Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@starnix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.starnix.com/ | 75D2 9EC4 C1C0 0599 13DA