新手问题 说个小坑

zsusyt · June 05, 2016 · Last by zsusyt replied at June 05, 2016 · 1704 hits

最近在玩 codingame 这个网站,初级 PUZZLE 的 MIME Type 中有个小坑(也可能是新手的误解)。 (ruby 2.0.0p647)

a = ".mp3."
a.split(".")

以为结果会是

["", "mp3", ""]

其实结果是

["", "mp3"]

查了下文档,原来 split 还有一个参数:

split(pattern=nil, [limit])  anArray

具体见这里 把 limit 设置为任意负值,就会得到

["", "mp3", ""]
You need to Sign in before reply, if you don't have an account, please Sign up first.