Page 1 of 1

arraytostring?

Posted: 25 Feb 2013 05:16
by mh175
The last piece of my puzzle. Now that I have my array

a={8,12,5}

I want to concatenate this into the number 8125

Not sure why but arraytostring just gives me a bunch of ''''''''' in my monitor. Not sure if I have the syntax right:

arraytostring(a[0, 1, 2])

Re: arraytostring?

Posted: 25 Feb 2013 19:13
by dBlicious
It's not obvious but arraytostring converts an array of ASCII codes to a string. For single-digit numbers you just need to add 48 to get the ASCII code. It's a little more complicated for numbers > 9. I wrote a function intToArray(n) that converts a number n with any number of digits to an array of ASCII codes. There's also a script arrayIntToArray(arr) that converts an array of numbers to an array of ASCII. Hope this helps.
IntegersToString.jzml
convert numbers to ASCII for use in arraytostring()
(10.52 KiB) Downloaded 163 times
-A

Re: arraytostring?

Posted: 28 Feb 2013 17:45
by alexbausw
Hello dBlicious,

Inspired by your idea and the lack of string-functions I made two scripts to generate strings out of an array of chars.
I searched the forum for anything that helps concatenate numbers with strings but didn't found anything. So I hope this is useful and not already done. :-)
Until now I had to use a list/array of object-names as a reference for object-related functions. With these scripts I can concatenate an array of chars (the fixed part of the object-names) with a variable part of the name as an increasing number i.e. in a for-loop.

Because my Lemur-Editor crashes every time I want to open your Module (I use lemur-editor on win7) i wrote my own int2array-Script, wich makes an array of digits out of every number.
But it only works for numbers with up to eight digits. Perhaps someone can see the bug in the script. :-)

Examplecode only to show the concept:

Code: Select all

decl objectname = {'m','y','f','a','d','e','r'};
decl numofaders = 25;
decl i;

for (i = 0; i < numofaders; i++)
{
        setexpression(findobject(charstostring({objectname, int2array(i)})), 'x', i^2);
}


best regards
Alex

Re: arraytostring?

Posted: 28 Feb 2013 20:32
by alexbausw
Hello again,

I found that int2array works fine to a size of 0xffffff7 for the integer value. This must be the maximum size for integer variables. But I think I will never use such a big index for an object. :-)

best regards

Alex

Re: arraytostring?

Posted: 02 Mar 2013 02:36
by dBlicious
Nice script, Alex. Yeah, Lemur seems to have some limitations that are not too difficult to run up against.

Re: arraytostring?

Posted: 09 Mar 2013 22:05
by dBlicious
I just realized I couldn't open my script either. :oops: This one should work better. It has the same max value limitation that Alex noted.
IntegersToString v2.jzml
integer to ascii array function
(3.31 KiB) Downloaded 188 times

Re: arraytostring?

Posted: 17 Mar 2013 13:09
by Macciza
Hi
Yeah - meant to mention that - I copied the script out of the .jzml anyway
And did some versions as well that do similar stuff - might post them later . .
Max value is 32bit limit . . .
Cheers
MM

Re: arraytostring?

Posted: 17 Mar 2013 14:17
by wul
just uploaded a useful ascii calculator in the modules section

eg
setattribute(text3,'content','min'); will result in the displayed text having quotation marks........ 'min' looks crap


name_array={109,105,110};}
Text object = arraytostring(name_array) will result in the ........ min looks much better {109,105,110} being the ascii code within lemur for the letters min

suppose the example could have used the string maj, dim, aug. i wonder what i've been working on recently

Re: arraytostring?

Posted: 02 May 2014 23:51
by aer
cheers for the ascii conversion script!

Incredibly helpful! Just made my life a hundred times easier :)