Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
separate a string of values into an array - noob
Mmcolli00 Mom
6/16/2009 3:50:00 PM
Hi. I am don't understand how to separate my string of filenames into an
array. For example, arrayDiscrep[0] outputs the whole array when I need
it to only output the first element at index 0 which would be filename:
234234. Do you know how I can separate each filename for the array?
Thanks MC
I have this directory of filenames.
234234.EXE 234234.EXE 234545.EXE 34543435.EXE 234563.EXE 24324345.EXE...
Dir["C:/DiscrepancyFiles/*EXE"].each do |disFile|
stringDisFile = File.basename(disFile).gsub("EXE,"")
arrayDiscrep = Array.new
arrayDiscrep = stringDisFile.to_a
puts arrayDiscrep[0]
end
--
Posted via
http://www.ruby-...
.
1 Answer
Siep Korteling
6/16/2009 4:45:00 PM
0
Mmcolli00 Mom wrote:
> Hi. I am don't understand how to separate my string of filenames into an
> array. For example, arrayDiscrep[0] outputs the whole array when I need
> it to only output the first element at index 0 which would be filename:
> 234234. Do you know how I can separate each filename for the array?
> Thanks MC
>
> I have this directory of filenames.
> 234234.EXE 234234.EXE 234545.EXE 34543435.EXE 234563.EXE 24324345.EXE...
>
> Dir["C:/DiscrepancyFiles/*EXE"].each do |disFile|
> stringDisFile = File.basename(disFile).gsub("EXE,"")
>
> arrayDiscrep = Array.new
> arrayDiscrep = stringDisFile.to_a
> puts arrayDiscrep[0]
> end
Everything between the "each"and "end" is a loop, so you are making a
new array for each file.
File.basename has a nice feature; if you specify a suffix it is removed.
ar = Dir["C:/DiscrepancyFiles/*EXE"].map do |dis_file|
File.basename(dis_file, ".exe")
end
puts ar[0]
hth,
Siep
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
separate a string of values into an array - noob
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password