From: andrew_queisser@... (andrew queisser) Date: 2002-02-01T06:54:09+09:00 Subject: Newbie question What's the best way to return a substring that consists of the first 4 words, if words are comma-delimited, e.g.: line = "1,2,3,4,5,6,7" line.GetFirstFour should return "1,2,3,4" My first choice was: line.split(",")[0..3].join(",") but that can't be very efficient. I tried to do an explicit loop but I couldn't get it any better than this: cIndex = 0 4.times do begin cIndex = line.index(",",cIndex) + 1 rescue NameError cIndex = -1 end end The rescue being necessary because some lines may only have 4 elements so there's no fourth comma. Any suggestions? Thanks, Andrew Queisser Hewlett Paqard