arraytostring?

Discuss Lemur and share techniques.
Post Reply
mh175
Newbie
Posts: 23
Joined: 06 Oct 2012 16:42

arraytostring?

Post 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])
dBlicious
Newbie
Posts: 25
Joined: 12 Jan 2013 06:49

Re: arraytostring?

Post 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 162 times
-A
alexbausw
Newbie
Posts: 5
Joined: 11 Feb 2013 14:51

Re: arraytostring?

Post 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
Attachments
charstostring.jzml
To call the script press "Execute".
The variables are set in the script in the button
(4.03 KiB) Downloaded 157 times
alexbausw
Newbie
Posts: 5
Joined: 11 Feb 2013 14:51

Re: arraytostring?

Post 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
dBlicious
Newbie
Posts: 25
Joined: 12 Jan 2013 06:49

Re: arraytostring?

Post by dBlicious »

Nice script, Alex. Yeah, Lemur seems to have some limitations that are not too difficult to run up against.
dBlicious
Newbie
Posts: 25
Joined: 12 Jan 2013 06:49

Re: arraytostring?

Post 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 187 times
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: arraytostring?

Post 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
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
wul
Regular
Posts: 181
Joined: 10 Apr 2012 13:25

Re: arraytostring?

Post 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
aer
Newbie
Posts: 4
Joined: 20 Jul 2012 19:17
Location: London, UK
Contact:

Re: arraytostring?

Post by aer »

cheers for the ascii conversion script!

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