Forum: Ruby on Rails word_wrap with hard break

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
cool_screen_name90001 (Guest)
on 2005-11-20 04:40
(Received via mailing list)
How can I force word_wrap to break text like this?

<% @text='abcdefghijklmnopqrstuvwxyz' %>

<%= word_wrap(@text, 10) %>

It appears to currently only break on space characters.

thanks
csn



__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
alex (Guest)
on 2005-11-20 20:10
(Received via mailing list)
CSN wrote:
> How can I force word_wrap to break text like this?
>
> <% @text='abcdefghijklmnopqrstuvwxyz' %>
>
> <%= word_wrap(@text, 10) %>
>
> It appears to currently only break on space characters.
>

Possibly ever-so-slight overkill:

<% require 'strscan'
scan = StringScanner.new(@text)
while b = a.scan(/.{0,10}/) -%>
<%= b %><br />
<% end -%>
alex (Guest)
on 2005-11-20 20:18
(Received via mailing list)
Alex Y. wrote:
>
> Possibly ever-so-slight overkill:
>
> <% require 'strscan'
> scan = StringScanner.new(@text)
> while b = a.scan(/.{0,10}/) -%>
> <%= b %><br />
> <% end -%>
>

Sod.  That was stupid.  I meant this:

<% require 'strscan'
scanner = StringScanner.new(@text)
while line = scanner.scan(/.{0,10}/) -%>
<%= line %><br />
<% end -%>

Apologies for the confusion...
This topic is locked and can not be replied to.