General

How can I concatenate strings?

Started by ahonoe on .

Sign in or create an account to join the conversation.

8 posts

Topic starter
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.
Here you go:
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.
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:

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