Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String Split not working

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.

like image 366
Adam Avatar asked Nov 28 '12 15:11

Adam


People also ask

Why split is not working for dot in Java?

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.

How do I split a string into string?

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.

How does string split work?

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.

Why does split return empty string?

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.


2 Answers

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

like image 121
Adam Avatar answered Sep 20 '22 08:09

Adam


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);
}
like image 32
Alberto Albares Avatar answered Sep 19 '22 08:09

Alberto Albares