批量扣费格式:
机构号+yymmdd+顺序号|总笔数|总金额||||||
序号|存折帐号|扣费金额|||0|||
序号|存折帐号|扣费金额|||0|||
序号|存折帐号|扣费金额|||0|||文本格式如下(共9笔记录):
440982023041013999|9|9383528||||||
1|605925021200000076|3950|||0|||
2|605924021200000390|11700|||0|||
3|605924021200000687|108389|||0|||
4|605925021200000734|13290|||0|||
5|605924021200001253|8491|||0|||
6|605924021200001261|2607|||0|||
7|605924021200001583|632|||0|||
8|605924021200002045|5293|||0|||
9|605925021200002406|2212|||0||
现在要求按照 存折帐号(如605925 021200000076)前面6位(605925)区分分割此文本文件,把他们分别存到多个文件中,并重新计算总金额和记录数(笔数)。
------------------------
文本1(605924):
440982023041013999|新笔数|新总金额||||||
1|605924021200000390|11700|||0|||
2|605924021200000687|108389|||0|||
3|605924021200001253|8491|||0|||
4|605924021200001261|2607|||0|||
5|605924021200001583|632|||0|||
6|605924021200002045|5293|||0|||
------------------------
文本2(605925):
440982023041013999|新笔数|新总金额||||||
1|605925021200000076|3950|||0|||
2|605925021200000734|13290|||0|||
3|605925021200002406|2212|||0||

解决方案 »

  1.   

    1. tstringlist
    2. textfile
    3. 文件流
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i,si : integer;
      s : string;
      t : array of TStringList;
      sfile : TStringList;
      tm : TStringList;
    begin
      sfile := TStringList.Create;
      sfile.LoadFromFile('d:\abc.txt');
      tm := TStringList.Create;
      tm.Clear;
      si := 1;
      for i := 1 to sfile.Count-1 do
      begin
        s := copy(sfile[i],3,6);
        if tm.IndexOf(s) = -1 then
        begin
          tm.Add(s);
          SetLength(t,si);
          t[si-1] := TStringList.Create;
          t[si-1].Add(sfile[0]);      t[si-1].Add(inttostr(t[si-1].Count)+copy(sfile[i],2,length(sfile[i])-1));
          inc(si);
        end else begin
          t[tm.IndexOf(s)].Add(inttostr(t[tm.IndexOf(s)].Count)+copy(sfile[i],2,length(sfile[i])-1));
        end;  end;
      for I := 0 to si-2 do
        t[i].SaveToFile('d:\'+inttostr(i)+'.txt');end;
      

  3.   

    s := copy(sfile[i],3,6);  
    ////////这样截取不妥,假如前面的序号是2位数呢,所以LZ还是稍微改一下