From: Rob Biedenharn Date: 2008-08-20T05:33:14+09:00 Subject: Re: Cut a string if length > n On Aug 19, 2008, at 4:08 PM, Pål Bergström wrote: > This seems to do the trick. Will it always work? > > lastspace = message.message[0..70].rindex(" ") > puts message.message[0..lastspace.to_i] You likely want an exclusive range unless you want the space at the end. message.message[0...lastspace.to_i] What if there's no space? Then perhaps: message.message[0..(lastspace || -1).to_i] Of course, that puts you back in the position of getting the full string rather than some truncated version with no more than your desired number of characters. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com