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

請問 ExtractStrings([' '], [' '], pchar(astr), itemlist) 在做什麼?

答題得分者是:pceyes
joana
一般會員


發表:35
回覆:70
積分:21
註冊:2005-09-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-06-30 16:25:37 IP:118.169.xxx.xxx 訂閱
請問各位大德,我有COPY 用INDY寫賣酸梅湯發EMAIL的程式,當中有下列之程式,不了解它在做什麼
ExtractStrings([' '], [' '], pchar(astr), itemlist),有查help ,但查不到 ExtractStrings之資料.
有那位大德可指導一下嗎?

整段程式碼如下:
function TForm1.parseline(astr: string): string;
var
itemlist: TStringList;
i: integer;
aitem: string;
afile: string;
astart: integer;
ext: string;
flag: boolean;
begin
flag:= false;
result:= astr;
itemList:= TStringList.Create;
ExtractStrings([' '], [' '], pchar(astr), itemlist);
for i:= 0 to itemlist.Count - 1 do begin
.....

END;
pedro
尊榮會員


發表:152
回覆:1187
積分:892
註冊:2002-06-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-06-30 16:59:41 IP:60.248.xxx.xxx 未訂閱
Unit
Classes
Description
Use ExtractStrings to fill a string list with the substrings of the null-terminated string specified by Content.

google吧
http://www.google.com.tw/search?hl=zh-TW&q=delphi ExtractStrings&meta=&aq=f

===================引 用 joana 文 章===================
ExtractStrings([' '], [' '], pchar(astr), itemlist),有查help ,但查不到 ExtractStrings之資料.
itemList:= TStringList.Create;
ExtractStrings([' '], [' '], pchar(astr), itemlist);


pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-06-30 17:01:36 IP:220.141.xxx.xxx 訂閱
Fills a string list with substrings parsed from a delimited list.
Unit
Classes
Category
string handling routines (null-terminated)
Delphi syntax:
function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;
C syntax:
extern PACKAGE int __fastcall ExtractStrings(TSysCharSet Separators,
TSysCharSet WhiteSpace, char * Content, TStrings Strings);
Description
Use ExtractStrings to fill a string list with the substrings of the null-terminated string specified by Content.
Separators is a set of characters that are used as delimiters, separating the substrings. Carriage returns, newline characters, and quote characters (single or double) are always treated as separators. Separators are ignored when inside a quoted string until the final end quote. (Note that quoted characters can appear in a quoted string if the quote character is doubled.)
WhiteSpace is a set of characters to be ignored when parsing Content if they occur at the beginning of a string.
Content is the null-terminated string to parse into substrings.
Strings is a string list to which all substrings parsed from Content are added. The string list is not cleared by ExtractStrings, so any strings already in the string list are preserved.
ExtractStrings returns the number of strings added to the Strings parameter.
Note: ExtractStrings does not add empty strings to the list.
------
努力會更接近成功
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-06-30 18:05:28 IP:220.141.xxx.xxx 訂閱
ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;
Separators 參數指定一組分割符,所有的子串都是用它們分割的。但是成對的引號內的分割符會被忽略
(例如:'一定|我們 "我一定|要成功|?")。
WhiteSpace 參數指定每個子串開頭被忽略的字元
(例如:[' ', '#', '.']則'我們|我們 '我們|一定|"我一定|要成功|?"')
Strings 參數用於接收分割後的各個子串。它的原有內容不會被清空。別忘了Create哦。
另外,EctractStrings不會把(忽略WhiteSpaces後的)空串加入到Strings中。
傳回值是 -> 分割後的數量
------
努力會更接近成功
編輯記錄
pceyes 重新編輯於 2008-06-30 18:09:16, 註解 無‧
aKnightChen@Hotmail.com
一般會員


發表:62
回覆:57
積分:23
註冊:2003-06-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-06-30 22:20:10 IP:116.21.xxx.xxx 訂閱
小弟用{}引了两个地方,
让它可以实现",a,"====>拆分成1>.空,2>.a,3>空
"a,,a"==>1>.a,2>.空,3>.a
我觉得更好用,特别是自已写字符串规则时,


function kExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar;
Strings: TStrings): Integer;
var
Head, Tail: PChar;
EOS, InQuote: Boolean;
QuoteChar: Char;
Item: string;
begin
Result := 0;
if (Content = nil) or (Content^=#0) or (Strings = nil) then Exit;
Tail := Content;
InQuote := False;
QuoteChar := #0;
Strings.BeginUpdate;
try
repeat
while Tail^ in WhiteSpace [#13, #10] do Tail := StrNextChar(Tail);
Head := Tail;
while True do
begin
while (InQuote and not (Tail^ in [QuoteChar, #0])) or
not (Tail^ in Separators [#0, #13, #10, '''', '"']) do Tail := StrNextChar(Tail);
if Tail^ in ['''', '"'] then
begin
if (QuoteChar <> #0) and (QuoteChar = Tail^) then
QuoteChar := #0
else if QuoteChar = #0 then
QuoteChar := Tail^;
InQuote := QuoteChar <> #0;
Tail := StrNextChar(Tail);
end else Break;
end;
EOS := Tail^ = #0;
if 1=1
{(Head <> Tail)and让它支持空串}
{(Head^ <> #0)让它支持空,比如:',1,',将拆成三段)}
then
begin
if Strings <> nil then
begin
SetString(Item, Head, Tail - Head);
Strings.Add(Item);
end;
Inc(Result);
end;
Tail := StrNextChar(Tail);
until EOS;
finally
Strings.EndUpdate;
end;
end;
編輯記錄
aKnightChen@Hotmail.com 重新編輯於 2008-06-30 22:21:10, 註解 無‧
joana
一般會員


發表:35
回覆:70
積分:21
註冊:2005-09-02

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-07-02 00:02:03 IP:118.169.xxx.xxx 訂閱
謝謝各位大德熱心的指導,所提供的資料可能須要稍為消化一下.
可否再請教一個問題,如果html裡有 [簡体字]or[Unicode碼] 可否add進去TStringList裡?
TStringList的內容如何show出來,是否須再add進去Tmemo裡才能看?
謝謝指導!
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-07-02 12:08:13 IP:122.118.xxx.xxx 訂閱
請另行至 輸入法與字型程式設計討論區(Delphi) 重新開版
===================引 用 joana 文 章===================
謝謝各位大德熱心的指導,所提供的資料可能須要稍為消化一下.
可否再請教一個問題,如果html裡有 [簡体字]or[Unicode碼] 可否add進去TStringList裡?
TStringList的內容如何show出來,是否須再add進去Tmemo裡才能看?
謝謝指導!
------
努力會更接近成功
joana
一般會員


發表:35
回覆:70
積分:21
註冊:2005-09-02

發送簡訊給我
#8 引用回覆 回覆 發表時間:2008-07-04 15:16:11 IP:118.169.xxx.xxx 訂閱
謝謝各位大德的無私指導,花了一些時間try ExtractStrings函數,總算搞清楚它在做什麼
不過我要更正一下,這可能是筆誤
WhiteSpace 參數指定每個子串開頭被忽略的字元
(例如:[' ', '#', '.']則'我們|我們 一定 我一定要成功 <-少了##)。

至於上次的問題,我會找時間再貼到Pceyes大德所說的輸入法與字型程式討論區

謝謝各位不私藏的大德!
編輯記錄
joana 重新編輯於 2008-07-04 15:18:16, 註解 無‧
系統時間:2024-04-26 18:42:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!