作者csihcs (非天夜翔)
站內java
標題Re: [問題] 關於string的API
時間Fri May 23 14:26:33 2008
※ 引述《superlubu (叔叔你人真好)》之銘言:
※ 引述《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 "", 所以會是
"boo:and:foo*"
->
"b","o","o:and:foo*"
->
"b","o","","o",":and:foo*"
->
"b","o","","o",":and:f","o","o*"
->
"b","o","","o",":and:f","o","","o","*"
->
"b","o","","o",":and:f","o","","o",""
在這邊我用 * 代表 String terminal char (字串結尾字元)
這幾行藍色字代表尚未處理的字串
這幾行紅色字代表處理後非區隔字串,結果所要的部份
這幾行綠色字代表處理後的區隔字串,結果是不保留這個部份
把 o 當分隔產生
"b","o","","o",":and:f","o","","o",""
因為是用 "o" 當分隔,所以 "o" 不會出現在結果陣列
結果就是
{
"b", "", ":and:f", "", "" }
然後因為 API 裡黃色的那個說明,Trailing empty strings are not included
所以正確的結果會是
{
"b", "", ":and:f" }
唉~~我也快看不懂有必要在補充這篇嗎
感覺 super 大已經說的很明白了呀 >"<
--
很多人以為 所以我要 其實我是個
我是
大學生 告訴大家 三十一歲的
怪叔叔
● ●/ ︿ ︿
/
勁\ <
勁 ●
ㄨ /\ ㄨ
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 147.8.127.102
※ 編輯: superlubu 來自: 147.8.127.102 (05/23 12:45)
推 upo:不好意思~請問為什麼連續的o中間會有一個empty string? 05/23 12:57
推 csihcs:因為是以 "o" 作為分隔,遇到 "o" 就分隔一次 05/23 13:01
推 upo:不好意思~再請問boo的第二個o後面為什麼沒有empty string呢??? 05/23 13:13
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.104.30.81
※ 編輯: csihcs 來自: 59.104.30.81 (05/23 14:40)
推 superlubu:最後那個 o 與 string termination char 間也有一個 "" 05/23 14:42
※ 編輯: csihcs 來自: 59.104.30.81 (05/23 17:14)