--=-n45ceapFh3FUjFYpze9/
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
we need to replace a whitespace with a <br> if the string is longer
then 30 chars (next whitespace after 30 chars)
all whitespace after 30 chars, or every whitespace after 30 chars?
eg. if
s = '... foo bar 42 '
^
^
30
do you want
s = '...<br>foo<br>bar<br>42<br>'
or
s = '...<br>foo bar 42 '
are you trying to create a string buffer that will wrap after 30 chars?
if so maybe something like this.
harp:~ > cat a.rb
def brwrap buf, opts = {'width' => 30}
width = Integer opts['width']
wrapped = ['']
buf.scan(%r/\S+/) do |token|
line = wrapped.last
unless line.size + token.size + 1 < width
line << "<br>\n"
wrapped << ''
line = wrapped.last
end
line << ' ' << token
end
wrapped.join
end
buf = <<-txt
one two three four five six seven
eight nine ten eleven twelve thirteen
fourteen fifteen sixteen seventeen eightteen
txt
puts(brwrap(buf))
harp:~ > ruby a.rb
one two three four five six<br>
seven eight nine ten eleven<br>
twelve thirteen fourteen<br>
fifteen sixteen seventeen<br>
eightteen
of course anything like this will fail if the buffer contains lines which have
no spaces AND are more than 30 chars long!
regards.
-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
===============================================================================