Page 1 of 1

ArraytoStr how does it work?

Posted: Tue May 24, 2022 2:00 pm
by Bugala
I have here this piece of code:

Code: Select all

t_sum = {"1", "2", "3"}

ForEach(t_sum, DebugPrint)
string = ArrayToStr(t_sum)
DebugPrint(string)
And as can be seen, string is empty.

I am trying to make a string that would be numbers, like "0.123" but cant I use ArrayToStr to do that?

Re: ArraytoStr how does it work?

Posted: Tue May 24, 2022 5:47 pm
by plouf
what os ?
here it prints
1 2
2 3
0 1

Re: ArraytoStr how does it work?

Posted: Tue May 24, 2022 6:30 pm
by Bugala
Yeah, that what it debugprints here too, problem is, it doesnt print the string.

There are two debugs in that code.

First one is to debugprint everything inside t_sum, which is the:

Code: Select all

1 2
2 3
0 1
Then I am trying to use ArraytoStr for that t_sum, to make it into a string.

What I expect to happen with the Debugprint(string) is to show:

Code: Select all

123
But that doesnt.

Re: ArraytoStr how does it work?

Posted: Tue May 24, 2022 8:38 pm
by plouf
firs row is the index of the element, second row is the value
that is because ForEach parase each element one by one each time

chechk following if helps more to understand

Code: Select all

t_sum = {"first1_position=0", "Second2", "Third3"}

ForEach(t_sum, DebugPrint)
string = ArrayToStr(t_sum)
DebugPrint(string)


t_sum2 = {["First_index_custom_name_pos_0"]=11,["Second_index_custom_name_pos_1"]=21,["Third_index_custom_name_pos2"]=31}

ForEach(t_sum2, DebugPrint)
string = ArrayToStr(t_sum2)
DebugPrint(string)

Re: ArraytoStr how does it work?

Posted: Wed May 25, 2022 12:35 am
by plouf
ok misunderstood origninal query

example in uses single quotes and seems to work
as ArrayToStr is declared to need codepoints and not strings ( A code point is numeric 65)

Code: Select all

t_sum = {'1', '2', '3'}

ForEach(t_sum, DebugPrint)
str$ = ArrayToStr(t_sum)
DebugPrint(str$)
so something like this does that

Code: Select all

t_sum = {"1","2","3"}

Global str$
Function AddStrings(index,value)
	str$ = str$..value
EndFunction

ForEach(t_sum, AddStrings)

DebugPrint(str$)

Re: ArraytoStr how does it work?

Posted: Wed May 25, 2022 8:44 am
by Bugala
That's surprising, I always thought using " or ' would both be the same.

So can someone explain what exactly is the difference between using " or ' technically speaking?

Re: ArraytoStr how does it work?

Posted: Wed May 25, 2022 9:31 am
by plouf
single is number , double is string

check GetType()

GetType('x') ---> returns #NUMBER
GetType(#STRING) ---> returns #NUMBER
GetType("What am I?") ---> returns #STRING

Re: ArraytoStr how does it work?

Posted: Wed May 25, 2022 9:40 am
by Bugala
That is very good to know. And actually very useful to me right now too as I am having this difficulty of trying to make sure my numbers are strings and not numbers.

Re: ArraytoStr how does it work?

Posted: Wed May 25, 2022 9:57 am
by plouf
however keep in mind that single quotes are official for single character not multi i.e. '123'
at least that what manual in Variables and constants -> 10.10 Character constants says