Re: [問題] java.util.regex.Pattern
※ 引述《coolcomm (coolcomm)》之銘言:
: http://ppt.cc/ZbBl
: 24:
: int number=Integer.parseInt(Pattern.compile("\\d*").matcher(capacity).group());
: 請問為什麼每次到了第24行就會拋出IllegalStateException?
: 剛剛把這行分開來寫 結果更奇怪了
: Pattern pattern=Pattern.compile("\\d*"); //在這行就拋出IllegalStateException
: 有人知道是發生什麼事嗎@@
呃... 推文是我搞錯... 去看一次 API
Matcher.group() :
Returns the input subsequence matched by the previous match.
而 Pattern.matcher() method 回傳的 Matcher 物件, 是未曾開始進行 match 動作的
所以你的那段 code 會一直 return IllegalStateException: No match found.
至於怎樣才能讓 matcher 跑起來.... 再去看看 API 文件吧.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 147.8.127.102
→
10/29 19:58, , 1F
10/29 19:58, 1F
→
10/29 19:59, , 2F
10/29 19:59, 2F
→
10/29 20:00, , 3F
10/29 20:00, 3F
→
10/29 23:04, , 4F
10/29 23:04, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):