[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Split an element in an array into different fields using :

Peter Loftus

12/19/2007 3:42:00 PM

Hey guys so i have a example of splitting elements in an array and
getting the third word. Im using spaces to split it. Anyone know how to
split it if i need to use : instead of spaces

arr = File.readlines("sample.txt")
arr.map! {|line| line.split("\s")[2]}
--
Posted via http://www.ruby-....

1 Answer

Farrel Lifson

12/19/2007 3:48:00 PM

0

On 19/12/2007, Peter Loftus <loftuz@gmail.com> wrote:
> Hey guys so i have a example of splitting elements in an array and
> getting the third word. Im using spaces to split it. Anyone know how to
> split it if i need to use : instead of spaces
>
> arr = File.readlines("sample.txt")
> arr.map! {|line| line.split("\s")[2]}

line.split(':')

Farrel