Question : Ruby - removing elements of a string in an array

Hello
I have been trying to strip out parts of a string resulting from an array.
In my array I have collected text files from a folder - result is as follows:
c:08082008.txt
c:09082008.txt
I then managed to remove the c: element and the result is as follows:
[["08082008.txt", "09082008.txt"]]
I do not want the [[ or ]] in my result .......... in short how can you remove multiple parts of a string in an array?
My attempt som far ....

a = [Dir.glob("c:\*.txt")]
puts a
b = a.inspect.gsub!("c:","") #reomoves the c: element
File.open("c:/aa.txt","w") do |sink|
  sink.write b.to_s
  end
puts b #unforunately in the file I get [[and ]] at beginning and end of file
...................................
In the folder are 2 files
08082008.txt
09082008.txt
I want the same represented in the output file as "08082008.txt","09082008.txt"
 Regards
Phil

Answer : Ruby - removing elements of a string in an array

It all depens if it's know location than array access is fine. If  it's  known string gsub etc will be  ok, othewiese one will have to use regular expressions.

In you case you know it' DEC you like to remove and the c: so this will do and it's after the c: so

 str[5,str,size]
irb(main):005:0> str[5,str.size]
=> "_xyz"
will do fine. if the DEC is in between you have to use gsub
"c:abcDEC_foobarz"
=> "c:abcDEC_foobarz"
irb(main):007:0> str[2,str.size].gsub("DEC", "")
=> "abc_foobarz"

There is not general answer, it depends on the data you have...

Regards
Friedrich
Random Solutions  
 
programming4us programming4us