Javascript 字符串拆分不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13608939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 12:28:43  来源:igfitidea点击:

String Split not working

javascriptmax-msp-jitter

提问by Adam

I'm having a problem with splitting strings in Javascript in Max/MSP.

我在 Max/MSP 的 Javascript 中拆分字符串时遇到问题。

outlet is the Max/MSP version of printf etc.

outlet 是 printf 等的 Max/MSP 版本。

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.

任何帮助都非常受欢迎。

回答by Adam

Big thanks to Aaron Kurtzhals . Hopefully the upvote in the comment counts towards your rep!

非常感谢 Aaron Kurtzhals。希望评论中的点赞计入您的代表!

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

干杯

回答by Rafael Millares

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);
}