[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

convert string to array with delimiter

Valentino Lun

11/5/2008 9:05:00 AM

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.
--
Posted via http://www.ruby-....

3 Answers

Farrel Lifson

11/5/2008 9:09:00 AM

0

2008/11/5 Valentino Lun <sumwo@yahoo.com>:
> I use str.scan(/\w+/), which give the following result

str.split( ' ' )

Farrel
--
Aimred - Ruby Development and Consulting
http://www....

Peña, Botp

11/5/2008 9:12:00 AM

0

RnJvbTogVmFsZW50aW5vIEx1biBbbWFpbHRvOnN1bXdvQHlhaG9vLmNvbV0gDQojIEhvd2V2ZXIs
IEkgZXhwZWN0IHRoZSByZXN1bHQgbGlrZSB0aGlzDQojIFsiZGV2L2xpc19ob21lXzcxMiIsICIy
MDk3MTUyIiwgIjEwNTI2NTYiLCAiMTA0NDQ5NiIsICI1MSUiLA0KIyAiL2FwcGwvbGlzL2hvbWUy
Il0NCiMgDQojIFBsZWFzZSBhZHZpc2Ugb24gaG93IHRvIGRvIGl0LiBUaGFuayB5b3UuDQoNCnJl
YWQgb24gc3RyaW5nIGZ4bnMsIHFyaSBTdHJpbmcjLiANCmhlcmUgaW4gdGhpcyBjYXNlIHlvdSBt
YXkgdXNlIFN0cmluZyNzcGxpdA0KDQp0cnkgZmlyc3QsIA0KDQogIHN0ci5zcGxpdA0KDQoobm90
ZSB3L291dCBhbiBhcmcpDQo=

Heesob Park

11/5/2008 9:16:00 AM

0

2008/11/5 Valentino Lun <sumwo@yahoo.com>:
> 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