unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function field(str:string): string;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
str:TStringList;
str1:string;
str2:string;
i:integer;
begin
Memo1.Lines.Clear;
str:=TStringList.Create;
if OpenDialog1.Execute then
begin
str.LoadFromFile(OpenDialog1.FileName);
for i:=0 to str.Count-1 do
begin
str1:=str.Strings;
str2:=field(str1);
Memo1.Lines.Add(str2);
end;
end;
end;
function TForm1.field(str:string): string;
var
s:TStringList;
i:integer;
begin
s:=TStringList.Create;
s.Delimiter :='-';
s.DelimitedText :=str;
for i:=0 to s.Count-1 do
begin
Result:=trim(s.Strings[0]);
end;
end;
end.
在Delphi7中调试通过,不知道能不能满足你的要求