全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1277
推到 Plurk!
推到 Facebook!

又是一个关于d2009,INDY的问题

答題得分者是:st33chen












[/code]

我想提取其中的问题数据。代码如下,但是总是会把',StatusBar1.Panels[1].Text) Length('');
statusbar1.Panels[1].Text :=copy(statusbar1.Panels[1].Text,p 2,10);

[/code]
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
編輯記錄
zhouying82 重新編輯於 2009-04-03 22:22:16, 註解 無‧
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-04-03 22:18:30 IP:116.230.xxx.xxx 訂閱
htm源文件为:
。。。
[code xml]
气温15℃/ 11℃16℃ / 11℃18℃ / 9℃20℃ / 10℃18℃ / 11℃19℃ / 10℃14℃ / 9℃
也弄进去,该怎么弄呢?

[code delphi]
var
rStream: TStringStream;
begin
rStream:= TStringStream.Create('', TEncoding.Default);
IdHTTP1.Get('http://qq.ip138.com/weather/zhejiang/hangzhou.htm',rstream);
statusbar1.Panels[1].Text :=rStream.DataString;
p:=pos('气温
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-04-04 08:43:27 IP:122.116.xxx.xxx 未訂閱
您好,
方法很多, 如果是我, 我會這麼做
-------------------
假設
< / t r > < t r >
< t d a l i g n = " c e n t e r " > 气 溫 < / t d >
< t d > 1 5 ℃ / 1 1 ℃ < / t d >
< t d > 1 6 ℃ / 1 1 ℃ < / t d >
< t d > 1 8 ℃ / 9 ℃ < / t d >
< t d > 2 0 ℃ / 1 0 ℃ < / t d >
< t d > 1 8 ℃ / 1 1 ℃ < / t d >
< t d > 1 9 ℃ / 1 0 ℃ < / t d >
< t d > 1 4 ℃ / 9 ℃ < / t d >
< / t r >
< t r >
存在 astr, 並注意每列尾都有兩個英文空白.
----------
mylist := tstringlist.create;
// 除掉前二列
astr := stringreplace(astr, '< / t r > < t r > ' #13#10 '< t d a l i g n = " c e n t e r " > 气 溫 < / t d > ' #13#10, '',[]);
// 除掉後二列
astr := stringreplace(astr, #13#10 '< / t r > ' #13#10 '< t r > ', '', []);
// 除掉所有 < t d >
astr := stringreplace(astr, '< t d >', '', [rfreplaceall]);
// 除掉所有 < / t d > 但保留每列的 crlf
astr := stringreplace(astr, ' < / t d >, '', [rfreplaceall]);
// 利用 stringlist 來切資料
mylist.text := astr;
// mylist 的每一列就是各筆溫度資料

參考一下.

----------------------------------

以上是我最近較常採用的方式,
另外, 有興趣的話也可以參考一下我以前寫的一些 取 html 中 < t a b l e > 資料的
functions

http://blog.xuite.net/st33chen/delphi/23157317
------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
編輯記錄
st33chen 重新編輯於 2009-04-04 08:47:57, 註解 無‧
st33chen 重新編輯於 2009-04-04 09:11:06, 註解 無‧
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-04-06 21:58:57 IP:124.77.xxx.xxx 訂閱
敢问ST大大,astr是指什么啊?
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
老大仔
尊榮會員


發表:78
回覆:837
積分:1088
註冊:2006-07-06

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-04-06 22:06:55 IP:59.114.xxx.xxx 未訂閱
就是String...
也就是
var astr : String;
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-04-06 22:17:56 IP:124.77.xxx.xxx 訂閱
谢谢楼上,另外还有,ST大大,你给我的连接打不开啊。
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#6 引用回覆 回覆 發表時間:2009-04-08 09:21:20 IP:122.116.xxx.xxx 未訂閱
以前為了分析網頁資料寫了一些關於讀取 h t m l 中 < t a b l e >資料的 functions,
最近, 看到 roviury 大大的啟示, 又正好您正在問, 所以我翻出來用 roviury 大大提示的 delete procedure
改寫了一下, 由於我比較習慣用 function, 所以把 delete 功能寫成一個 cropstr function.
還沒測, 您要幫我測的話, 歡迎哦.
參考一下.

// 以下是新版 html functions : 引用網友介紹的 delete 改寫舊版, 看起來比較清爽
// 並加註解

// 把 procedure delete 改成 function 型, 比較習慣
function cropstr(htmstr: string; bgnpos, numchars: integer) : string;
begin
result := htmstr;
delete(result, bgnpos, numchars);
end;
// 找到 < t a b l e 並去掉本身及其前面子字串
function findtable(htmstr: string) : string;
var ii: integer;
begin
result := htmstr;
ii:=pos('< T A B L E',uppercase(result)); // 怕會影響顯示, 加空格
if ii>0 then result := cropstr(result, 1, ii 5)
end;
// 找到 < t r 並去掉本身及其前面子字串
function findtr(htmstr: string) : string;
var ii:integer;
begin
result := htmstr;
ii:=pos('< T R',uppercase(result);
if ii>0 then result := cropstr(result,1, ii 2);
end;
// 跳到第一個 tag 外的字元,
// 例如跳到 < t d > < f o n t ...>資料< / f o n t>< / t d > 中的 資 字
function skiptag(htmstr : string) : string;
var ii:integer;
begin
result := result:='<' htmstr;
while copy(result,1,1)='<' do begin
ii:=pos('>',result);
result := trim(cropstr(result, 1, ii));
end;
end;
// 找到 < t d 並跳到第一個 tag 外的字元, 也就是他的資料
function findtd(htmstr : string) : string;
var ii:integer;
begin
result := htmstr;
ii:=pos('< T D',uppercase(result));
if ii>0 then begin
result := cropstr(result, 1, ii-1);
while copy(result,1,1)='<' do begin
ii:=pos('>',result);
result := trim(cropstr(result, 1, ii));
end;
end;
end;
// 找到 < t h 並跳到第一個 tag 外的字元, 也就是他的資料
function findth(htmstr : string) : string;
var ii:integer;
begin
result := htmstr;
ii:=pos('< T H',uppercase(result));
if ii>0 then begin
result := cropstr(result, 1, ii-1);
while copy(result,1,1)='<' do begin
ii:=pos('>',result);
result := trim(cropstr(result, 1, ii));
end;
end;
end;

// 取得 td 或 th 的資料(在 findtd 或 findth 後使用)
function getdata(var htmstr: string) :string;
var ii:integer;
begin
ii:=pos('<',htmstr)-1;
result := trim(copy(htmstr,1,ii));
delete(htmstr,1, ii);
end;
// 去掉 < t d > 到 < / t d > 也就是去掉一欄資料
function skiptd(htmstr : string) : string;
var ii,jj:integer;
begin
result := htmstr;
ii:=pos('< T D',uppercase(result));
if ii>0 then begin
result := trim(cropstr(result, 1, ii 2));
end;
ii := pos('< / T D',uppercase(result));
if ii>0 then begin
result := trim(cropstr(result, 1, ii 4));
end;
end;
// 找到某字串並去掉本身及其前面子字串, 保持原大小寫
// 主要用在去掉目標 < t a b l e 之前的一大段廢話.
function findstr(astr:string; htmstr:string) : string;
var ii:integer;
begin
result := htmstr;
ii := pos(astr, result);
if ii>0 then begin
result := cropstr(result, 1, ii length(astr)-1);
end;
end;
------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
編輯記錄
st33chen 重新編輯於 2009-04-08 09:26:36, 註解 無‧
系統時間:2024-05-19 11:46:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!