Yes, I admit that I was not very clear
(English's not my mother tongue.. ;-) ):
An input text file (@source) looks like this:
0000022340
0023457000
0000000110
0008000000
0000090000
0000330000
0000000730
0664000000
0034000000
or maybe:
AGCTAGCT12345
AAA3BBBCC
AAACC
@source[i][j] = ASCII substring at this position:
e.g.: val = @source[1][3] #-> "3"
by non-convertible I mean everything that cannot be
represented as an integer ("12345678A", "A".to_i # -> "0")
Array a) yields in Array a)
Array a) yields in 0000000012345
0000000000000
0000000000000
I managed to obtain such structures, but not by the Ruby way...
David A. Black wrote:
> Hi --
>
> On Thu, 13 Oct 2005, Peter v. N. wrote:
>
>> Hi all,
>>
>> Once again I disturb you for a, maybe, obvious thing
>> I can't figure out.
>>
>> I have successfully created an md array (see older posts
>> from me) thanks to the support found here.
>>
>> Now I would like to list all String items in the source array
>> (a Text file containing numbers) and convert and place them into the
>> destination array as int objs. I know about the String#split method
>> but this recreates an array that does not match the dimensions I want
>> (e.g. lines with different length).
>>
>> My approach is very c-ish:
>>
>> <code>
>> # @source is a String array. If the string contains a non-convertible
>> # substring, 0 is placed in destination array. @array is the
>> destination # md array created with the appropriate dimensions
>> according to @source # (longest line as vindex (-) and index as hindex
>> (|) )
>>
>> for i in 0... / hindex.length
>> for j in 0...@vindex[i].length
>> @array[i][j] = @source[i][j].to_i.char.to_i
>> end
>> end
>> </code>
>>
>> Is there a Ruby way to replace <code> with blocks?
>
>
> I'm not quite sure what's what here. I thought @vindex was the length
> of the longest string, but then what's @vindex[i]?
>
> Also, what would constitute a non-convertible substring?
>
> Can you clarify, or maybe provide a small example of desired
> input/output?
>
>
> David
>