Forum: Ruby on Rails String split help

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Fresh M. (Guest)
on 2009-01-24 00:27
I have string: "xxx | yyy | zzz | ddd"

I need to split it to: "xxx", "yyy", "zzz" and "ddd",
make link to every word like: <a href="xxx">xxx</a>

So result must by:

from this:  "xxx | yyy | zzz | ddd"  to this:

"<a href="xxx">xxx</a>, <a href="yyy">yyy</a>, <a href="zzz">zzz</a>, <a

How can I do it?
Philip H. (Guest)
on 2009-01-24 00:30
(Received via mailing list)
> a>, <a
> href="ddd">ddd</a>"
> How can I do it?

"xxx | yyy | zzz | ddd".split(){}....join()

I'll let you figure out what goes into the () and {}'s :)
Andrew B. (Guest)
on 2009-01-24 18:15
(Received via mailing list)
"xxx | yyy | zzz | ddd".split(" | ") # => ["xxx", "yyy", "zzz", "ddd"]
This topic is locked and can not be replied to.