作者TonyQ (骨头)
看板java
标题Re: [J2SE] html的文字能当成string用吗?
时间Sun Apr 15 23:25:52 2007
※ 引述《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)