使用此代码: "\t\ttest\t\t\t".split(/\t/) 我期待以下结果: = ["", "", "test", "", "", ""] 但结果是: = ["", "", "test"] 为什么? 如果省略limit参数,则返回的空字段将保留在返回的数组之外.如果是否
"\t\ttest\t\t\t".split(/\t/)
我期待以下结果:
=> ["", "", "test", "", "", ""]
但结果是:
=> ["", "", "test"]
为什么?
如果省略limit参数,则返回的空字段将保留在返回的数组之外.如果是否定的,则返回:# Supply -1 as the limit parameter "\t\ttest\t\t\t".split(/\t/, -1) => ["", "", "test", "", "", ""]
这在String.split()
documentation.中有详细说明