如何将命令arg正确地拆分为有组织的数组? [关闭]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将命令arg正确地拆分为有组织的数组? [关闭]相关的知识,希望对你有一定的参考价值。

所以,假设你有这个字符串:

alert the message 'Howdy World!'

我怎么能把它整齐地分成一个数组:

["alert", "the message", "Howdy World!"]

此外,这可以用于:

alert the message 'How are you?' to the player

['alert', 'the message', 'How are you?', 'to the player']

如果你能解释我怎么可能做到这一点,那就太好了。

编辑:

“alert”是命令名称,

“命令”是一串额外的词,

“'你好吗?'”是重要的信息,而且

“对玩家来说”是一串额外的单词。

这可能会被放入

<command> <extra> <important> <extra>

如果有可能的方法来分隔字符串

alert the message 'How are you?' to the player

['alert', 'the message', "'How are you?'", 'to the player']

那就是我想要找到的。

答案

你需要这样做..说

var string = "'alert' 'the message' 'How are you?' 'to the player'"
var result  = string.split("''");
window.alert(result);

以上是关于如何将命令arg正确地拆分为有组织的数组? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章