請問如何在多個文字檔裡找尋相同字串 |
尚未結案
|
dopopodo
一般會員 發表:2 回覆:1 積分:0 註冊:2005-08-01 發送簡訊給我 |
如題,我現在用的方式是一個文字檔一個String,所以說有7個文字檔的話就有7個String,為了方便我把String整合在Array裡面。現在的問題是說,一個String很長(100多個字),那說不定有3個文字檔其中一段是相同的(文字一模一樣),如何把他找出來呢?謝謝 我的delphi壓縮起來了,在這可以下載,裡面有範例文字檔(hjj5542.txt, hjj5543.txt)
http://rapidshare.de/files/6294384/copy.zip.html {Author: Dopopodo
Date: 15-October-2005
Description: Find and matches the part of strings Modification History
Date Modifier Description
=============================================================
15-Oct-05 PL Draft coding, interface
designed. }
unit copy; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls; type
TTest = record
sText : string;
sFileName : string;
end; type
TfrmCopy = class(TForm)
dlgOpen: TOpenDialog;
pnlFile: TPanel;
memFiles: TMemo;
btnOpen: TButton;
memText: TMemo;
lblCount: TLabel;
pnlMatch: TPanel;
btnMatch: TButton;
lblResult: TLabel;
procedure btnOpenClick(Sender: TObject); private
{ Private declarations }
FaText: array[1..1000] of TTest;
FiCount: integer;
procedure FileRead(sFileName: string);
public
{ Public declarations }
end; var
frmCopy: TfrmCopy; implementation {$R *.dfm} //************************************************************************** procedure TfrmCopy.btnOpenClick(Sender: TObject);
{Purpose: To read the text files from users requests.
Input Parameter: N/A
Output Parameter: N/A
}
begin
if dlgOpen.Execute then
begin
FiCount := StrToInt(lblCount.Caption);
memFiles.Lines.Add(dlgOpen.FileName);
FileRead(dlgOpen.FileName);
end;
end; //************************************************************************** procedure TfrmCopy.FileRead(sFileName: string);
{Purpose: To read and process the files which has been opened.
Input Parameter: sFileName - string
Output Parameter: N/A
}
var
fInput: TextFile;
sText: string;
begin
Inc(FiCount);
AssignFile(fInput, sFilename);
Reset(fInput); while (not EOF (fInput)) do
begin
ReadLN(fInput,sText);
FaText[FiCount].sText := sText;
memText.Lines.Add(FaText[FiCount].sText);
end; memText.Lines.Add('=====================================================');
lblCount.Caption := IntToStr(FiCount);
end; //************************************************************************** end.
|
abona
一般會員 發表:1 回覆:1 積分:0 註冊:2002-10-25 發送簡訊給我 |
建議你可以從 TStringList 下手.
題外話:類似在文字檔裡找尋字串的問題,在 UNIX 及 LINUX 上有一專章
「正規表示式」在討論,功能相當強大,
在許多 script 均有支援,如 JavaScript,Perl,PHP,SED,AWK
提供一網頁供你參考:
http://main.rtfiber.com.tw/~changyj/regex.1/index.html
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |