各位前辈 我刚刚学用DELPHI开发,
请指教我提的第一个问题:
1文本记录用户信息:
姓名 帐号 交易次数 交易金额
Xxx xxx xx xxxx
….
…
2文本记录详细交易信息
姓名 帐号 交易金额
Xxx xxx yyy
Xxx xxx zzz
…
…
让运行结果存到一个新文件:
姓名 帐号 交易次数 交易金额
Xxx xxx xx+2 xxxx+yyy+zzz
...
...一行一行的读2文本,累加金额和次数到1文本中对应的用户信息中,请指点如何实现,具体的代码该如何写
非常感谢,急!
请指教我提的第一个问题:
1文本记录用户信息:
姓名 帐号 交易次数 交易金额
Xxx xxx xx xxxx
….
…
2文本记录详细交易信息
姓名 帐号 交易金额
Xxx xxx yyy
Xxx xxx zzz
…
…
让运行结果存到一个新文件:
姓名 帐号 交易次数 交易金额
Xxx xxx xx+2 xxxx+yyy+zzz
...
...一行一行的读2文本,累加金额和次数到1文本中对应的用户信息中,请指点如何实现,具体的代码该如何写
非常感谢,急!
WriteLnTStringList的Add也可以
list1,list2:TStringList;
begin
list1:=TStringList.Create ;
list1.LoadFromFile('c:\1.txt');
list2:=TStringList.Create ;
list2.LoadFromFile('c:\2.txt');
list1.AddStrings(list2);
showmessage(list1.Text );end;
我把问题简化了,是很长数据的银行交易的文本,我试了看看。搞定了我把分全送给你们啊
我被催着。。
可以参考 delphi7 从入门到精通
的 Using the Jet Engine 这一章,
变成数据库的操作,接下来,就简单点Text Files through Jet
One of the most useful IISAM drivers that comes with the Jet engine is the Text IISAM. This driver allows you to read and update text files of almost any structured format. We will begin with a simple text file and then cover the variations. Assume you have a text file called NightShift.TXT that contains the following text: CrewPerson ,HomeTown
Neo ,Cincinnati
Trinity ,London
Morpheus ,Milan
Add an ADOTable component to a form, set its ConnectionString to use the Jet 4.0 OLE DB provider, and set Extended Properties to Text. The Text IISAM provider considers a directory a database, so you need to enter as the database name the directory that contains the NightShift.TXT file. In the Object Inspector and drop down the list of tables in the TableName property. You will notice that the dot in the filename has been converted to a hash, as in NightShift#TXT. Set Active to True, add a DataSource and a DBGrid and connect them altogether, and you will see the contents of the text file in a grid. Warning If your computer's settings are such that the decimal separator is a comma instead of a period (so that 1,000.00 is displayed as 1.000,00), then you will need to either change your Regional Settings (Start ® Settings ® Control Panel ® Regional Settings ® Numbers) or take advantage of SCHEMA.INI, described shortly.
The grid indicates that the widths of the columns are 255 characters. You can change these values just as you did in the JetExcel program by adding persistent fields or columns to the grid and then setting the relevant width property. Alternatively, you can define the structure of the text file more specifically using SCHEMA.INI.In the JetText example, the database folder is determined at run time depending on the folder hosting the program. To modify the connection string at run time, first load it into a string list (after converting the separators) and then use the Values property to change only one of the elements of the connection string. This is the code from the example: procedure TForm1.FormCreate(Sender: TObject);
var
sl: TStringList;
begin
sl := TStringList.Create;
sl.Text := StringReplace (ADOTable1.ConnectionString,
';', sLineBreak, [rfReplaceAll]);
sl.Values ['Data Source'] := ExtractFilePath (Application.ExeName);
ADOTable1.ConnectionString := StringReplace (sl.Text,
sLineBreak, ';', [rfReplaceAll]);
ADOTable1.Open;
sl.Free;
end;