我正在寻找一种方法来拆分这个字符串数组:
["this", "is", "a", "test", ".", "I", "wonder", "if", "I", "can", "parse", "this",
"text", "?", "Without", "any", "errors", "!"]
将文本按标点符号分组:
[
["this", "is", "a", "test", "."],
["I", "wonder", "if", "I", "can", "parse", "this", "text", "?"],
["Without", "any", "errors", "!"]
]
有没有一种简单的方法来做这件事?最明智的方法是遍历数组,将每个索引添加到临时数组中,并在找到标点符号时将该临时数组附加到容器数组中吗?
我想使用 slice
或 map
,但我无法确定是否可能。