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.
backslash-dot is invalid because Java doesn't need to escape the dot. You've got to escape the escape character to get it as far as the regex which is used to split the string. eg.
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
The string split() method breaks a given string around matches of the given regular expression. After splitting against the given regular expression, this method returns a string array.
The natural consequence is that if the string does not contain the delimiter, a singleton array containing just the input string is returned, Second, remove all the rightmost empty strings. This is the reason ",,,". split(",") returns empty array.
Big 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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With