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

问题描述 投票:0回答:1

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

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']

那就是我想要找到的。

javascript arrays arguments
1个回答
2
投票

你需要这样做..说

var string = "'alert' 'the message' 'How are you?' 'to the player'"
var result  = string.split("''");
window.alert(result);
© www.soinside.com 2019 - 2024. All rights reserved.