General

arraytostring?

Started by mh175 on .

Sign in or create an account to join the conversation.

9 posts

Topic starter
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])
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

-A
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:
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

charstostring.jzml
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
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