Convert string to array with delimiter

Dear all

I have the following string want to convert to arry

str="/dev/lis_home_712 2097152 1052656 1044496 51%
/appl/lis/home2\n"

I use str.scan(/\w+/), which give the following result
[“dev”, “lis_home_712”, “2097152”, “1052656”, “1044496”, “51”, “appl”,
“lis”, “home2”]

However, I expect the result like this
[“dev/lis_home_712”, “2097152”, “1052656”, “1044496”, “51%”,
“/appl/lis/home2”]

Please advise on how to do it. Thank you.

2008/11/5 Valentino L. [email protected]:

I use str.scan(/\w+/), which give the following result

str.split( ’ ’ )

Farrel

From: Valentino L. [mailto:[email protected]]

However, I expect the result like this

[“dev/lis_home_712”, “2097152”, “1052656”, “1044496”, “51%”,

“/appl/lis/home2”]

Please advise on how to do it. Thank you.

read on string fxns, qri String#.
here in this case you may use String#split

try first,

str.split

(note w/out an arg)

2008/11/5 Valentino L. [email protected]:

However, I expect the result like this
[“dev/lis_home_712”, “2097152”, “1052656”, “1044496”, “51%”,
“/appl/lis/home2”]

Please advise on how to do it. Thank you.

str.scan(/\S+/)
or
str.split(/\s+/)
or
str.split

Regards,

Park H.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs