convert string to array with delimiter

V

Valentino Lun

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.
 
P

Peña, Botp

RnJvbTogVmFsZW50aW5vIEx1biBbbWFpbHRvOnN1bXdvQHlhaG9vLmNvbV0gDQojIEhvd2V2ZXIs
IEkgZXhwZWN0IHRoZSByZXN1bHQgbGlrZSB0aGlzDQojIFsiZGV2L2xpc19ob21lXzcxMiIsICIy
MDk3MTUyIiwgIjEwNTI2NTYiLCAiMTA0NDQ5NiIsICI1MSUiLA0KIyAiL2FwcGwvbGlzL2hvbWUy
Il0NCiMgDQojIFBsZWFzZSBhZHZpc2Ugb24gaG93IHRvIGRvIGl0LiBUaGFuayB5b3UuDQoNCnJl
YWQgb24gc3RyaW5nIGZ4bnMsIHFyaSBTdHJpbmcjLiANCmhlcmUgaW4gdGhpcyBjYXNlIHlvdSBt
YXkgdXNlIFN0cmluZyNzcGxpdA0KDQp0cnkgZmlyc3QsIA0KDQogIHN0ci5zcGxpdA0KDQoobm90
ZSB3L291dCBhbiBhcmcpDQo=
 
H

Heesob Park

2008/11/5 Valentino Lun said:
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.

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

Regards,

Park Heesob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top