Posted on 2007-07-06 19:39
dennis 閱讀(414)
評(píng)論(0) 編輯 收藏 所屬分類:
動(dòng)態(tài)語(yǔ)言
用了這么久ruby,知道String對(duì)象可以通過(guò)[]操作得到字符或者子字符串,比如:
>"abc"[0]
97
>"abc"[0,2]
"ab"
97就是字符a的ASCII碼了,卻不知道[]操作同樣可以接受正則表達(dá)式,返回匹配正則的那部分字符串,比如:
>"has 5 and 3" [/\d+/]
5
>"hello there"[/(..)e/]
the
ruby的API設(shè)計(jì)充分體現(xiàn)了馬教主所說(shuō)的
人本接口。