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
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
Alex Young wrote:> 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 -%> >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... -- Alex