VB.net - grouping identical values then manipulating the result -


i have found similar questions none hit looking for. lets have array of 10 values fruit :

fruit(1) = "apple" fruit(2) = "orange" fruit(3) = "banana" fruit(4) = "cherry" fruit(5) = "peach" fruit(6) = "" fruit(7) = "" fruit(8) = "" fruit(9) = "" fruit(10) = "" 

now, have statement says fruit(6)="apple", making array :

fruit(1) = "apple" fruit(2) = "orange" fruit(3) = "banana" fruit(4) = "cherry" fruit(5) = "peach" fruit(6) = "apple" fruit(7) = "" fruit(8) = "" fruit(9) = "" fruit(10) = "" 

i want have sub group items , store once. so,

fruit(1) = "2 x apple" fruit(2) = "orange" fruit(3) = "banana" fruit(4) = "cherry" fruit(5) = "peach" fruit(6) = "" fruit(7) = "" fruit(8) = "" fruit(9) = "" fruit(10) = ""  

and next time add apple goes "3 x apple" , on.

so in pseudo code want

look duplicate values count how many duplicates  alter original item delete newly altered entry 

what's simplest , elegant way in vb.net? there way without linq?

@the_lotus right, can use dictionary

   dim fruits new dictionary(of string, integer)     sub addfruit(fruitname string)       if fruits.containskey(fruitname)          fruits.item(fruitname) += 1       else          fruits.add(fruitname, 1)       end if    end sub 

and return

   function numberoffruit(fruitname string) string       return fruits.item(fruitname) & " x " & fruitname    end function 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -