文件内格式为dword  id,dword length,string,byte length2,other. 然后循环。 
怎样转为文本文件。  
id=1  str=你好  other=其他
另:如果上面的格式用%d,%d%s,%b%s来表示。  
那另一文件%d,%d,%d%s,怎样写一个通用的处理程序。

解决方案 »

  1.   

    帮你写个大概的程序吧
    procedure txtProc(s: string);
    var
      st: TStringList;
      i: integer;
    function Split(s, t: string): TStringList;
    begin
      Result := TStringList.Create;
      while SPos(t, s)>0 do
      begin
         Result.Add(Copy(s, 1, SPos(t, s)-1));
         Delete(s, 1, SPos(t, s));
      end;
      if Length(s)>0 then Result.Add(s);
    end;
    begin
      st := TStringList.Create;
      st := Split(s, ',');
      for i:=0 to (st.Count div 3)-1 do
        Memo1.Lines.Add('id='+st[3*i+0]+#9+'str='+st[3*i+1]+#9+'other='+st[3*i+2]);
      st.Free;
    end;
      

  2.   

    原理是,将字符串已“,”分离,装入一个TStringList,然后从TStringList中一次取三个字符串,格式话显示在Memo中。没有考虑健壮性,需要的话可以自己改。现在的程序,需要完全按照格式id,str,other,id,str,other,....
      

  3.   

    忘了补上SPos函数了,目的是Pos的时候不区分大小写,这里就不用了,你直接把SPos改为Pos
    function TForm1.SPos(t, s: string): integer;
    begin
      Result := Pos(AnsiLowerCase(t), AnsiLowerCase(s));
    end;
      

  4.   

    01 00 00 00->1
    04 00 00 00->4
    31 32 33 34->4字节1234
    05->5
    31 32 33 34 35->5字节12345
      

  5.   

    那你可以用Copy函数依次读取数据
      

  6.   

    cuteant的程序完全错了
    我以前做过这样的东西,贴一小段  //跳过消息头
      ContentIndex:=8;  //提取发言人信息
      Move(Msg[ContentIndex],ContentLen,2);
      Inc(ContentIndex,2);
      SetLength(Ret.Sender,ContentLen);
      Move(Msg[ContentIndex],Ret.Sender[1],ContentLen);
      Inc(ContentIndex,ContentLen);