From: John Joyce Date: 2007-03-13T01:35:27+09:00 Subject: Re: Efficiency of string parsing Excellent sollution for coding efficiency. (though, I always think Regular Expressions should be commented well (broken into parts) due to the terseness of the syntax, especially for those who don't use RegEx regularly. (no pun, really) But would a Ruby iterator be faster? Clearly this is a tool to wrap text to 50 characters per line without breaking words. Curious to see more ideas/approaches on that. On Mar 13, 2007, at 12:30 AM, Robert Klemme wrote: > On 12.03.2007 16:23, Kev wrote: >> I have written a loop to basically parse a string, and at every 50th >> character check to see if is a space, if not, work back until it >> finds one, then insert a newline. I am turning masses of text (copy) >> from a DB into images, and I just wanted to automate it, I was just >> wondering if there are better ways of achieving what I am trying to >> do. > There are quite a lot of posts about word wrapping which seems what > you are trying to do. You should be able to find them via the > archives (Google Groups, ruby-talk archive). > > A simplistic approach would probably do something like this: > > str.gsub(/(.{1,50})\s+/, "\\1\n") > > Kind regards > > robert >