[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

string question

Bu Mihai

12/18/2007 10:02:00 AM

i have this string:
try_dir="program files/tbla/bla1"

how can i slice it in string1=program files" string2="tbla"
string3="bla1"

tnx
--
Posted via http://www.ruby-....

3 Answers

Lee Jarvis

12/18/2007 10:52:00 AM

0

Bulhac Mihai wrote:
> i have this string:
> try_dir="program files/tbla/bla1"
>
> how can i slice it in string1=program files" string2="tbla"
> string3="bla1"

>> try_dir = "program files/tbla/bla1"
=> "program files/tbla/bla1"
>> string1, string2, string3 = try_dir.split('/')
=> ["program files", "tbla", "bla1"]
>> string1
=> "program files"
>> string2
=> "tbla"
>> string3
=> "bla1"

String#split

HTH

Regards,
Lee


--
Posted via http://www.ruby-....

Lloyd Linklater

12/19/2007 2:18:00 AM

0

Bulhac Mihai wrote:
> i have this string:
> try_dir="program files/tbla/bla1"
>
> how can i slice it in string1=program files" string2="tbla"
> string3="bla1"

ar = Array.new
ar = "program files/tbla/bla1".split("/")
p ar

=> ["program files", "tbla", "bla1"]
--
Posted via http://www.ruby-....

Sebastian Hungerecker

12/19/2007 1:58:00 PM

0

Lloyd Linklater wrote:
> ar = Array.new
> ar = "program files/tbla/bla1".split("/")

The array created by Array.new will be replaced by the array created by split
in the very next line and thus never be used. In other words: you can leave
the first line out.


--
Jabber: sepp2k@jabber.org
ICQ: 205544826