Page 1 of 1
How can I concatenate strings?
Posted: 31 Mar 2012 20:10
by ahonoe
Hi All,
Apologies if this has been asked and answered. I'm trying to figure out how to build strings dynamically in Lemur by concatenating a series of smaller strings. Ideally I would store the smaller strings in an array.
I am using the wonderful Missing Link (OSC over WiFi to MIDI box)
wifimidi.com. The ML parses incoming OSC strings (addresses) containing MIDI hex data and sending the MIDI to its output.
What I'd like to do is assemble these OSC strings on-the-fly based on user input in Lemur.
Any suggestions would be appreciated.
Re: How can I concatenate strings?
Posted: 01 Apr 2012 07:48
by bxsj
Here you go:
Code: Select all
decl str1={1,2,3};
decl str2={4,5};
decl str3={7,8,9,0x0A};
decl string;
string={str1,str2,str3};
Hope that helps,
B.
Re: How can I concatenate strings?
Posted: 01 Apr 2012 14:17
by ahonoe
Thanks bxsj. I'll give this a try.
Regards,
Scott
Re: How can I concatenate strings?
Posted: 04 Jun 2012 17:24
by bxsj
Unfortunately there is no real string handling available. The "strings" in the example above are actually arrays containing an entry for each character in ASCII. Saying that, displaying a string like yours could like this:
Code: Select all
decl txtsharpy={47,115,104,97,114,112,121,47};
decl i=3;
decl parameter={67,111,108,111,114,87,104,101,101,108,32,53};
decl s = arraytostring({ txtsharpy, i+48, 47, parameter });
setattribute(Text,'content',s);
Not sure if this helps,
B.
Re: How can I concatenate strings?
Posted: 04 Jun 2012 19:18
by bxsj
decl s = arraytostring({ '/sharpy/', i+49, '/', 'ColorWheel' });
doesn't work? Is there any way to make that work?
The array with a character per character approach is the only way I am aware of. Perhaps in a future version of Lemur?
If I have to replace all of these strings with ascii arrays it is going to be quite a big pain! (and be potentially quite bug-prone).
You could define the common used strings as variables (expressions), so that they are only defined once to avoid bugs.
E.g.: expression txtsharpy = {47,115,104,97,114,112,121,47} Then use "txtsharpy" whenever you need it in an osc command.
/sharpy/1/Dimmer 0.234
Not sure if values like 0.234 can be converted into an array.
Good Luck,
B.
Re: How can I concatenate strings?
Posted: 05 Jun 2012 12:36
by bxsj
Great job, really slick
Yep, I agree some more string functions would be helpfull.
Cheers,
B.
Re: How can I concatenate strings?
Posted: 20 Jan 2013 16:56
by dBlicious
Thanks for this. You saved me hours.
-A
Re: How can I concatenate strings?
Posted: 26 Jan 2013 01:00
by shanekoss
thanks for posting this - very cool. One question. What if the lemur object is the variable as opposed to message you wanted to send?
using the example above - what if the object you are referring to is the variable that you've defined with your arraytosring
like this:
setattribute(s, 'content', 'test'); // check address string
or in my case:
setexpression(s, 'x', 1); // turn button on
can't seem to make that work. i've confirmed s is correct (in this case s = LOOPER1.record, which is the name of the object i want to set the expression of) If i replace s with LOOPER1.record, it works, but with the declared variable s, it doesn't.
Any ideas?
Thanks!