views:

376

answers:

1

User inputs a comma separated string and i d like to make a an associative array out of it as follows : Input : 4,3,3,2,2 Output : Array{"0"=>4,"1"="3","2"=>3,"3"=>2,"4"=>2}

I can create an array by input.text.split(",");

But I d like to make it an associative array as above, how to do this?

Thanks.

+1  A: 

Well, besides the fact that an array like the one you've got there is already 'associative' -- associated with numbers starting at 0. So:

yourArray[0] // will be 4
yourArray[3] // will be 2

If you want to associate with something else -- like strings -- then you might want to look into the Dictionary class.

thenduks
Or, for String keys, use raw Object instances.
Michael Brewer-Davis
Yea, that link explains the difference between `Dictionary` and `Object`.
thenduks