Re: [問題] 關於string的API
※ 引述《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)
推
05/23 12:57,
05/23 12:57
推
05/23 13:01,
05/23 13:01
推
05/23 13:13,
05/23 13:13
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.104.30.81
※ 編輯: csihcs 來自: 59.104.30.81 (05/23 14:40)
推
05/23 14:42, , 1F
05/23 14:42, 1F
※ 編輯: csihcs 來自: 59.104.30.81 (05/23 17:14)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
java 近期熱門文章
3
14
PTT數位生活區 即時熱門文章