cardanver,
Cita:
|
...tengo un archivo arch1.txt...tengo que hacer un arch2.txt de posición fija...'NNN DD/MM/YYYY HH:MM'...
|
Revisa este código:
Código Delphi
[-]
procedure TForm1.Button1Click(Sender: TObject);
const
IFileName = 'IFile.txt';
OFileName = 'OFile.txt';
var
InputFile : TStringList;
OutputFile : TStringList;
AuxFile : TStringList;
AuxStr : String;
i : Integer;
begin
try
InputFile := TStringList.Create;
OutputFile := TStringList.Create;
AuxFile := TStringList.Create;
InputFile.LoadFromFile(IFileName);
for i := 0 to InputFile.Count - 1 do
begin
ExtractStrings([' ',':'], [], PChar(InputFile[i]), AuxFile);
AuxFile[0] := Format('%.3d',[StrToInt(AuxFile[0])]);
AuxFile[2] := Format('%.2d',[StrToInt(AuxFile[2])]);
AuxFile[3] := Format('%.2d',[StrToInt(AuxFile[3])]);
AuxStr := AuxFile[0] + ' ' + AuxFile[1] + ' ' + AuxFile[2] + ':' + AuxFile[3];
OutputFile.Add(AuxStr);
AuxFile.Clear;
end;
OutputFile.SaveToFile(OFileName);
MessageDlg('Archivo de Salida Generado Satisfactoriamente',mtInformation,[mbYes],0);
finally
InputFile.Free;
OutputFile.Free;
AuxFile.Free;
end;
end;
El código anterior
asume que la fecha del archivo de entrada viene en el formato
DD/MM/AAAA como se indica en el
Msg #1 y
genera un archivo de salida en el formato
'NNN DD/MM/YYYY HH:MM', según se indica en el requerimiento planteado.
Espero sea útil
Nelson.