所以,假设你有这个字符串:
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);