文字列を分解する
(Professional 版以上) あるセパレータで文字を分解したい事がたまにあります。HTTPAppユニットにはそんな要望に応える ExtractHTTPFields関数というものが用意されています。名前からも解るとおり、本来は http://〜 の文字列を分解するための関数のようです。
■ 文字列を分解する例 |
procedure TForm1.FormCreate(Sender: TObject); var strValue : string; chrSepa,chrWhite : TCharSet; sltResult : TStringList; begin { 対象文字列 } strValue := 'http://www.borland.co.jp/delphi/technical/tec0010.html'; { 結果をセットする TStrings互換型 } sltResult := TStringList.Create; sltResult.Clear; { セパレータ いくつでもOK } chrSepa := ['/','.']; { 無視する文字、これもいくつでもOK } chrWhite := ['w']; { 分解 } ExtractHTTPFields(chrSepa,chrWhite,PChar(strValue),sltResult); { 結果を ListBoxへ (ExtractHTTPFields( 〜,ListBox1.Items); でもOK } ListBox1.Items.Assign(sltResult); sltResult.Free; end; |
※ uses節 に HTTPAppを追加してください。
[結果]
http:
borland
co
jp
delphi
technical
tec0010
html