ArraytoStr how does it work?

Find quick help here to get you started with Hollywood
Post Reply
Bugala
Posts: 1040
Joined: Sun Feb 14, 2010 7:11 pm

ArraytoStr how does it work?

Post 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?

plouf
Posts: 264
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: ArraytoStr how does it work?

Post by plouf »

what os ?
here it prints
1 2
2 3
0 1
Christos

Bugala
Posts: 1040
Joined: Sun Feb 14, 2010 7:11 pm

Re: ArraytoStr how does it work?

Post 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.

plouf
Posts: 264
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: ArraytoStr how does it work?

Post 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)
Christos

plouf
Posts: 264
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: ArraytoStr how does it work?

Post 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$)
Christos

Bugala
Posts: 1040
Joined: Sun Feb 14, 2010 7:11 pm

Re: ArraytoStr how does it work?

Post 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?

plouf
Posts: 264
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: ArraytoStr how does it work?

Post by plouf »

single is number , double is string

check GetType()

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

Bugala
Posts: 1040
Joined: Sun Feb 14, 2010 7:11 pm

Re: ArraytoStr how does it work?

Post 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.

plouf
Posts: 264
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: ArraytoStr how does it work?

Post 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
Christos

Post Reply