作者AmosYang (LetMeGoogleThatForYou)
看板java
标题Re: [问题] String.split
时间Mon Jul 5 05:54:44 2010
※ 引述《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)
1F:→ jlovet:是,你说的对,javadoc的确有说他为什麽跟其他语言都要做不 07/05 06:13
2F:→ jlovet:一样,是我没有看清楚,不好意思 07/05 06:15