Re: [問題] 關於string的API

看板java作者 (叔叔你人真好)時間17年前 (2008/05/23 12:42), 編輯推噓4(400)
留言4則, 3人參與, 最新討論串2/3 (看更多)
※ 引述《upo (誰說這是個公平的世界)》之銘言: : 標題: [問題] 關於string的API : 時間: Fri May 23 12:22:44 2008 : split : public String[] split(String regex)根據給定正則運算式的匹配拆分此字串。 : 該方法的作用就像是使用給定的運算式和限制引數 0 來呼叫兩引數 split 方法 : 。因此,所得陣列中不套件括結尾空字串。 : : 另外在 Regex 結果 : : { "boo", "and", "foo" } : o { "b", "", ":and:f" } ←這裡 : 所以我說... 看 API 還是去看英文版的好... 阿六版的翻譯實在是比英文更難懂 f-.- Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the giv en expression and a limit argument of zero. Trailing empty strings are therefo re not included in the resulting array. boo:and:foo 用 o 來當成 seperator,連續的 o 中間有一個 empty string "", 所以會是 "b", "o", "", "o", ":and:f", "o", "", "o", "" 結果就是 { "b", "", ":and:f", "" } 然後因為 API 裡黃色的那個說明,Trailing empty strings are not included 所以正確的結果會是 { "b", "", ":and:f" } -- 很多人以為 所以我要 其實我是個 我是大學生 告訴大家 三十一歲的怪叔叔 ● ●/ ︿ ︿ /\ < ● ㄨ /\ ㄨ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 147.8.127.102 ※ 編輯: superlubu 來自: 147.8.127.102 (05/23 12:45)

05/23 12:57, , 1F
不好意思~請問為什麼連續的o中間會有一個empty string?
05/23 12:57, 1F

05/23 13:01, , 2F
因為是以 "o" 作為分隔,遇到 "o" 就分隔一次
05/23 13:01, 2F

05/23 13:13, , 3F
不好意思~再請問boo的第二個o後面為什麼沒有empty string呢???
05/23 13:13, 3F

05/23 14:51, , 4F
API 已經說了不會 include 啦... =_=
05/23 14:51, 4F
文章代碼(AID): #18DaiXX4 (java)
討論串 (同標題文章)
文章代碼(AID): #18DaiXX4 (java)