Is there an easy way to create a string of an integer array?
(Other than reading all items in array , converting each to string , and then concatenate.)
This does not work:
DIm s as string
s = join( str(numbers(),";")
if array integer contents is ; 1,2,3,4
the string should be “1,2,3,4”
[quote=430298:@Enric Herrera]Thanks, I agree with Aaron I have to do it manually
Public Function ArrayIntToString(n() as integer) as string
dim s() as string
for each i as integer in n()
s.append str( i )
next
return join(s,";")
End Function[/quote]
CAUTION:
A For…Each loop does not guarantee that it will loop through the values in the array in index order.
So there is no guarantee that your integer array will have the same order as your string array.
Better use a “regular” For … Next loop if order matters.
[quote=430435:@Stefan Adelsberger]CAUTION:
A For…Each loop does not guarantee that it will loop through the values in the array in index order.
So there is no guarantee that your integer array will have the same order as your string array.
Better use a “regular” For … Next loop if order matters.[/quote]
Thank’s Stefan, I’m aware of this, but in that case, order is not relevant.
Norman, you’re right but is good to be aware of this because the documentation says:
“Do not make any assumptions of the traversal order as it is subject to change in the future.”
Yeah - But joe was the compiler engineer so him saying “unlikely to change” is about as close to “its not changing” as you’ll get
esp if you’re dealing with an array where a sensible iterator goes from 0 to ubound
with other data types (say a dictionary) if the underlying representation was to move to some kind of tree then its very plausible the ordering could change. or even moving it from a hashmap keyed one way to one keyed differently then the order could change.