From: "Guy N. Hurst" Date: 2002-03-23T05:15:34+09:00 Subject: Re: Sub-String Sean O'Dell wrote: > > "Mike Stok" wrote in message > news:slrna9n27u.v47.mike@ratdog.stok.co.uk... > > 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, > > Yeah, that worked great, thank you. Where did you learn to do that? I > bought three Ruby books and even now that I know how to do that, I can't > find reference to that anywhere. I must be missing something. > Which books did you buy? "The Ruby Way" book has an entry in the index: 2 Simple Data Tasks Strings : Accessing and Assigning Substrings .... 71 Pages 71-72 describe various possibilities. Guy N. Hurst