MyStr:=Copy(aString,1,SepCharPos-1); //将分割符前所有字符放到mystr串中
Delete(aString,1,SepCharPos);//除去分割符和分割符前的子串
GetSubStr:=MyStr;//返回一个字段
end;
FunctionTforml.GetSubStrNum(aString:String;SepChar:String):Integer;
var
i:Integer;
StrLen:Integer;
Num:Integer;
begin
StrLen:=Length(aString);
Num:=0;
for i:=1 to StrLen do
if Copy(aString,i,1) = SepCharthen
Num:=Num+1;
GetSubSrtNum:=Num;
end;
有了上面三个函数,现在介绍一下具体的应用:
1.首先建立一个窗体Forml,加入一个RichEditl(或Menol),一个按钮Buttonl和一个Tablel,设置Tablel的属性:
Tablell.DataBase = ''c:\Archivs''
Tablell.TableName =''Archive.dbf''
2.分别加入以下
程序:
Const Space= ''''
ProcedureTForml.FormCreate(Sender:Tobject);
begin
RichRditl.Lines.LoadFromFile(''Archive.txt'');
end;
ProcedureTForml.Button1Click(Sender:Tobject);
var
i,j:Integer;
MyLine:String;
begin
with Tablel do
begin
Open;
for i:=0 to RichEditl.Lines.Count-1 do
begin
MyLine:=RegulateStr(Richeditl.Lines[i],Space);
for j:=1 to Num do
begin
Append;
fileds[j-1].aString:=GetSubSrt(MyLine,Space));
post;
end;
end;
end;
end;