这段代码如何写啊? ( 积分: 50 )

  • 主题发起人 主题发起人 huxhang
  • 开始时间 开始时间
H

huxhang

Unregistered / Unconfirmed
GUEST, unregistred user!
文本文件:1qq.text的内容:
"MB3","MB1","MB0" //此行替换为1:
"3","","0" //此行替换为30,
"","1","0" //此行替换为10,
"3","","0" //此行替换为30,
"3","1","" //此行替换为31
"MB3","MB1","MB0" //此行替换为2:
"3","1","0" //此行替换为310,
"","1","0" //此行替换为10,
"","","" //此行替换为 ,
"3","1","" //此行替换为31,

.....还有很多行

如何将上面替换为:
1:30,10,30,31
2:310,10, ,31

.....还有很多行

这段代码如何写啊?
 
var
List: TStrings;
i, ID, Count: integer;
begin
List:= TStringList.Create;
try
List.LoadFromFile('1qq.txt');
List.Text:= StringReplace(List.Text, '"', '', [rfReplaceAll]);
List.Text:= StringReplace(List.Text, ',', '', [rfReplaceAll]);
List.Text:= StringReplace(List.Text, ' ', '', [rfReplaceAll]);
i:= 0; ID:= 0; Count:= 0;
while i < List.Count do
begin
if Copy(List,1,1) = 'M' then
begin
ID:= i;
List[ID]:= IntToStr(ID + 1) + ':';
Count:= 0;
i:= i + 1;
end
else begin
if Count > 0 then List[ID]:= List[ID] + ',';
List[ID]:= List[ID] + List;
Count:= Count + 1;
List.Delete(i);
end;
end;
finally
List.Free;
end;
end;
 
接受答案了.
 
后退
顶部