Any Idea for
how to identify different string values in a string
a$=“10,20,35,100,100,50,50”
i need to count like by grouping
Ej:
2=100
2=50
Any Idea for
how to identify different string values in a string
a$=“10,20,35,100,100,50,50”
i need to count like by grouping
Ej:
2=100
2=50
Use Split to get the individual values and use a Dictionary to count them.
dim a as string = "10,20,35,100,100,50,50"
dim s() as string = split(a, ",")
dim k as string
dim i, n as integer
dim dict as new dictionary
for i = 0 to ubound(s)
n = dict.Lookup(s(i), 0)
dict.value(s(i)) = n+1
next
for each k in dict.keys
n = dict.value(k)
msgbox str(n) + "="+ k
next
Hi Tim you the Best
thanks for this big idea
Hi Tim
this works but i have second value that is parts of the string
dim a as string = “10:1,20:3,35:3,100:1,100:1,50:2,50:2”
so i need the number of groups and the value
EJ; 2=100 and value =2
2=50 and value=4
how i can store on the dictionary
or save the second value in other dictionary and look it by like index or on array
Right. Accumulate the value in another dictionary. So instead of storing the count and incrementing by one, you will store the value and add the next value to the total.
dim s1, s2 as string
s1 = NthField(s(i), ":", 1)
s2 = NthField(s(i), ":", 2)
n = dict.lookup(s1, 0)
dict.value(s1) = n+1
n = dict2.lookup(s1, 0)
dict2.value(s1) = n + val(s2)
thanks