作者superlubu (叔叔你人真好)
看板java
标题Re: [问题] 关於string的API
时间Fri May 23 12:42:07 2008
※ 引述《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)
1F:推 upo:不好意思~请问为什麽连续的o中间会有一个empty string? 05/23 12:57
2F:推 csihcs:因为是以 "o" 作为分隔,遇到 "o" 就分隔一次 05/23 13:01
3F:推 upo:不好意思~再请问boo的第二个o後面为什麽没有empty string呢??? 05/23 13:13
4F:推 adrianshum:API 已经说了不会 include 啦... =_= 05/23 14:51