Re: [J2SE] html的文字能當成string用嗎?
※ 引述《brianpcbest (FF4)》之銘言:
: 首先謝謝板主跟TonyQ的熱心回文
: testStr是我漏打了一行 testStr = testStr + lineStr;
: 我一開始採取TonyQ的建議
: 因為我抓的跳離點是怪怪的沒錯~一開始沒想到那麼多
: 不過試了一下~用正則表示式還是比對不到字串
: 程式依然會把整個網頁讀完才停止
: http://0rz.tw/062ye
: 這是原始檔~裡面是用TonyQ的方法
: 不過我自己試endString去相等也是沒有辦法跳離
: 是寫法上出了什麼問題?
你的 code 這樣只有前面允許 後面還是要完全比對
if(testStr.matches(".*【20[0-9]{2}/[0-1][0-9]/[0-3][0-9] 聯合報】"))
break;
應該改成 indexOf()!=-1
或者是
if(testStr.matches(".*【20[0-9]{2}/[0-1][0-9]/[0-3][0-9] 聯合報】.*"))
break;
詳情把regex讀懂就知道了XD
--
另外需要做String疊加的話
用StringBuffer會有更棒的效能 ,
--
String temp="relax"; | Life just like programing
while(buringlife) String.forgot(temp); | to be right or wrong
while(sleeping) brain.setMemoryOut(); | need not to say
stack.push(life.running); | the compiler will
stack.push(scouting.buck()); | answer your life
stack.push(bowling.practice()); | Bone everything
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.27.68
※ 編輯: TonyQ 來自: 220.134.27.68 (04/15 23:27)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 5 之 5 篇):