3
有了這個代碼:紅寶石字符串分割意想不到的結果
"\t\ttest\t\t\t".split(/\t/)
我希望以下結果:
=> ["", "", "test", "", "", ""]
但結果是:
=> ["", "", "test"]
爲什麼?
有了這個代碼:紅寶石字符串分割意想不到的結果
"\t\ttest\t\t\t".split(/\t/)
我希望以下結果:
=> ["", "", "test", "", "", ""]
但結果是:
=> ["", "", "test"]
爲什麼?
如果省略了限制參數,則會在返回的數組之外放置結尾空字段。如果是負數,他們將返回:
# Supply -1 as the limit parameter
"\t\ttest\t\t\t".split(/\t/, -1)
=> ["", "", "test", "", "", ""]
酷詳細!謝謝!我發現官方文檔確實提到了限制,但我不知道「null」是指空字符串。 – 2012-02-10 07:24:57