delphi TXT格式转化

来源:百度知道 编辑:UC知道 时间:2024/07/07 04:16:28
LB U0 [10]LUMBER Sep '1013:13:20257.0s
4.8257.0257.0257.0
LB X0 [10]LUMBER Nov '1013:13:20255.0s
10.0255.0255.0255.0
LB F1 [10]LUMBER Jan '1113:13:20245.0s
0.0245.0
如何转换成下述格式
LB X0 [10],LUMBER Nov
'10,13:13:20,255.0s,10.0,255.0,255.0,255.0
LB F1 [10],LUMBER Jan
'11,13:13:20,245.0s, 0.0,245.0
数据都是TXT格式文档,求详细方法

function convert(const str1: string; const str2: string): string;
var
s1: string;
s2: string;
tmp: string;
idx: integer;
tm1: string;
i: integer;
list: TStrings;
begin
s1 := str1;
s2 := str2;
tmp := Copy(s2, Length(s2) - 6 + 1, 6);
s1 := StringReplace(s1, '''', #$D#$A'''', [rfReplaceAll]);
idx := Pos(tmp, s1);
Delete(s1, idx + 1, Length(tmp)+1);
Insert(', ', s1, Length(s1) - 8 + 1);
tm1 := '';
list := TStringList.Create;
try
list.Delimiter := '.';
list.DelimitedText := s2;
for i := 0 to List.Count - 2 do begin
tm1 := tm1 + IntToStr(StrToInt(list.Strings[i])) + '.0, ';
end;
delete(tm1, Length(tm1), 1);
finally
list.Free;
end;<