string question

B

Bulhac Mihai

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

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

tnx
 
L

Lee Jarvis

Bulhac said:
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
 
L

Lloyd Linklater

Bulhac said:
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"]
 
S

Sebastian Hungerecker

Lloyd said:
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.
 

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

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,055
Latest member
RacheleCar

Latest Threads

Top