Hi Johnathan,
> I have an ASCII file that looks like:
>
> 1 0 3 0 4
> 4 3 2 9 8
> 3 0 9 9 7
>
> I am able to store each whole line as an seperate array. But I cannot
> find out how I can get the input of that file and store it into a double
> array. For example, 1 would be array[0][0], and 7 would be array[4][2].
Are those spaces separating each item, or did you just put that in for
readability? No worries, it''s similar either way.
Assuming you''ve already used readlines() to read all the
file''s lines
into an array you can then do this:
array.map! do |line| line.split // end
Splitting on an empty regexp divides a string into individual
characters. But for space-delimited characters you can just use the
default split using whitespace, which makes things even easier:
array.map! do |line| line.split end
Regards,
Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---