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

刪除網頁的標籤

答題得分者是:harpist
astro0803
一般會員


發表:18
回覆:30
積分:9
註冊:2007-05-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-06-05 16:54:17 IP:122.123.xxx.xxx 訂閱
如題,我將一個網頁抓回來之前,要將其標籤刪除,可是一直會有問題,但我就是不知道問題所在,之後我就自己新增類似網頁標籤的字串來測試,便發現是會多刪一個字之類的,但真正的問題我目前還沒找出來,程式碼如下:    <textarea cols="60" rows="10" class="cpp" name="code"> void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString word="000000Xx" ; word.Delete(word.AnsiPos("<"),word.AnsiPos(">")); Memo1->Lines->Add(word); } </textarea>
harpist
資深會員


發表:3
回覆:251
積分:430
註冊:2002-10-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-06-05 20:15:00 IP:211.74.xxx.xxx 未訂閱
<textarea class="cpp" rows="10" cols="60" name="code">AnsiString::Delete Removes a specified number of characters from the string. AnsiString& __fastcall Delete(int index, int count); Description Delete modifies the AnsiString to remove count characters from the string beginning with the character at index, where 1 is the index of the first character. It returns the resulting modified string (*this). If index is larger than the length of the AnsiString or less than 1, no characters are deleted. If count specifies more characters than remain starting at the index, Delete removes the rest of the string. If count is less than 0, no characters are deleted. </textarea>

AnsiString::Delete 不是如你這樣用的喔

<textarea class="cpp" rows="10" cols="60" name="code">void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString word="000000Xx" ; int pos_start = word.AnsiPos("<"); int pos_end = word.AnsiPos(">"); while(pos_start!=0 && pos_end!=0) { word.Delete(pos_start,pos_end-pos_start 1); pos_start = word.AnsiPos("<"); pos_end = word.AnsiPos(">"); } Memo1->Lines->Add(word); } </textarea>

------
~§~迷時師渡,悟了自渡~§~
編輯記錄
harpist 重新編輯於 2007-06-05 23:03:05, 註解 修改變數名稱‧
astro0803
一般會員


發表:18
回覆:30
積分:9
註冊:2007-05-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-06-05 21:42:41 IP:122.123.xxx.xxx 訂閱
奇怪,那我一開始是設這樣有錯嗎?不是跟你的差不多= =" 到底是那有問題呢?可以跟我解釋一下嗎?    <textarea cols="60" rows="10" class="cpp" name="code"> while(word.AnsiPos("<")!=0) { pos_start=word.AnsiPos("<"); pos_end=word.AnsiPos(">"); word.Delete(pos_start,pos_end); Memo1->Lines->Add(word); } </textarea>
harpist
資深會員


發表:3
回覆:251
積分:430
註冊:2002-10-03

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-06-05 23:05:24 IP:211.74.xxx.xxx 未訂閱
我修改了變數名稱你參考看看
主要在於你對於 AnsiString::Delete 的用法錯誤。
------
~§~迷時師渡,悟了自渡~§~
astro0803
一般會員


發表:18
回覆:30
積分:9
註冊:2007-05-28

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-06-06 15:28:11 IP:122.123.xxx.xxx 訂閱
我終於知道了^^
系統時間:2024-04-25 20:08:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!