String question

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-forum.com/.

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-forum.com/\.

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-forum.com/\.

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