I'm having a problem with splitting strings in Javascript in Max/MSP.
outlet is the Max/MSP version of printf etc.
The string splits weirdly, but it seems to only output both words comma seperated.
function sample_callback(args) // Callback
{
var keyword=args;
var trackname=keyword.toString().split(" ");
var name = trackname[0]; // trackname[1] outputs nothing.
outlet(0, name);
}
Any help is greatly received.
I'm having a problem with splitting strings in Javascript in Max/MSP.
outlet is the Max/MSP version of printf etc.
The string splits weirdly, but it seems to only output both words comma seperated.
function sample_callback(args) // Callback
{
var keyword=args;
var trackname=keyword.toString().split(" ");
var name = trackname[0]; // trackname[1] outputs nothing.
outlet(0, name);
}
Any help is greatly received.
Share Improve this question edited Nov 28, 2012 at 16:09 Adam asked Nov 28, 2012 at 15:46 AdamAdam 4931 gold badge5 silver badges16 bronze badges 5 |2 Answers
Reset to default 12Big thanks to Aaron Kurtzhals . Hopefully the upvote in the comment counts towards your rep!
A simple overlooked checking of what the string is helped me out. oops. The working code is now..
function sample_callback(args) // Callback
{
var keyword=args.toString();
var trackname=keyword.split(",");
var name = trackname[0];
outlet(0, name);
}
Cheers
function sample_callback(args) // Callback
{
var keyword=args.toString()`enter code here`;
var trackname=keyword.toString().split(" ");
var name = trackname[0]; // trackname[1] outputs nothing.
outlet(0, name);
}
sample_callback
, and the definition ofoutlet
. BTW: if you're coming from a C/C++ background, bear in mind that JS has more in common with Scheme/Lisp, so treat functions as objects (pass them as arguments/return values at will) – Elias Van Ootegem Commented Nov 28, 2012 at 15:51keyword.toString()
? – Aaron Kurtzhals Commented Nov 28, 2012 at 16:07