Re: [問題] String.split

看板java作者 (LetMeGoogleThatForYou)時間15年前 (2010/07/05 05:54), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/3 (看更多)
※ 引述《jlovet ( )》之銘言: : → jlovet:你這麼厲害為什麼不要解釋一下為什麼會有空白 07/05 05:04 javadoc 已經寫得很清楚,提供了足夠的資訊給想追根究底的人 java.* 下的 source code 也已經開出來給你看 有那個時間嗆不如腳踏實地作學問 http://www.docjar.com/html/api/java/util/regex/Pattern.java.html 205 public String[] split(CharSequence inputSeq, int limit) { 206 ArrayList res = new ArrayList(); 207 Matcher mat = matcher(inputSeq); 208 int index = 0; 209 int curPos = 0; 210 211 if (inputSeq.length() == 0) { 212 return new String [] {""}; //$NON-NLS-1$ 213 } else { 214 while (mat.find() && (index + 1 < limit || limit <= 0)) { 215 res.add(inputSeq.subSequence(curPos, mat.start()).toString()); 216 curPos = mat.end(); 217 index++; 218 } 219 220 res.add(inputSeq.subSequence(curPos, inputSeq.length()).toString()); 221 index++; 222 223 /* 224 * discard trailing empty strings 225 */ 226 if (limit == 0) { 227 while (--index >= 0 && res.get(index).toString().length() == 0) { 228 res.remove(index); 229 } 230 } 231 } 232 return (String[]) res.toArray(new String[index >= 0 ? index : 0]); 233 } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 65.87.177.87 貼了 source code 後…排版爆炸了…算了,懶得修了 XD ※ 編輯: AmosYang 來自: 65.87.177.87 (07/05 06:06)

07/05 06:13, , 1F
是,你說的對,javadoc的確有說他為什麼跟其他語言都要做不
07/05 06:13, 1F

07/05 06:15, , 2F
一樣,是我沒有看清楚,不好意思
07/05 06:15, 2F
文章代碼(AID): #1CCGCf6U (java)
討論串 (同標題文章)
文章代碼(AID): #1CCGCf6U (java)