From: Harry Kakueki Date: 2007-06-01T21:04:48+09:00 Subject: Re: Getting the last N bytes of a string: On 6/1/07, Brian Candler wrote: > What's the simplest way to get only the last 10 bytes of a string? > > buf[-10,10] > > doesn't work if buf is smaller than 10 bytes, as it returns nil. Is there > anything simpler than > > buf[-10,10] || buf > > ? > > Thanks, > > Brian. > > P.S. To get the *first* 10 bytes of a string is easy: buf[0,10] always > works, whether or not buf is smaller than 10 bytes) > > I don't know if this is simple but you can try something like this. str =~ /(.{1,10}$)/ Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/