Joao Pedrosa
10/11/2004 3:19:00 PM
Hi,
On Mon, 11 Oct 2004 12:09:39 -0300, Joao Pedrosa <joaopedrosa@gmail.com> wrote:
> Hi,
>
> On Mon, 11 Oct 2004 11:22:52 -0300, Joao Pedrosa <joaopedrosa@gmail.com> wrote:
> > Hi,
> >
> > On Mon, 11 Oct 2004 23:06:58 +0900, J.Lang <jlang@ywesee.com> wrote:
> > > we need to replace a whitespace with a <br> if the string is longer
> > > then 30 chars (next whitespace after 30 chars)
> > >
> > > does someone have a idea to programm this in ruby?
My last try, as I had forgotten to adjust the example. I changed the
creation of the sample string and made sure the space is substituted
correctly:
5.times{
s = '0123456789 ' * (rand * 10)
p "s (#{s.size}): #{s}"
z = ''
while s do
if s.size <= 30
z += s
break
else
i = s[30..-1].index(' ') || s.size
i += 30
z += s[0...i]
s = s[i+1..-1]
if s
z += '<br />'
end
end
end
p '---z---', z, '-------'
}
Cheers,
Joao