这个函数应该满足你的要求
procedure CSV_ImportData(vfile: string);
var
Buff: string;
fd: TStringList;
I,vConut,vNumber,n: Integer;
vStr,vChar,vShow: String;
begin
if not FileExists(vfile) then
Exit;
I := 1;
vChar := '';
vStr := '';
vShow := '';
fd := TStringList.Create;
try
fd.LoadFromFile(vfile);
if fd.Count > 0 then begin
Buff := fd[0];
Buff := Trim(Buff);
vConut := Length(Buff);
while I < Length(Buff) do begin
vNumber := 0;
vStr := Copy(Buff,I,1);
if (vStr = '') or (vStr = Null) then
Inc(I)
else begin
if (vStr = '"') and ((vChar = '') or (vChar = ',')) then begin
vNumber := 1;
while I < vConut do begin
Inc(I);
if ((Copy(Buff,I,1) = '"') and (Copy(Buff,I+1,1)= '"')) then begin
vShow := vShow + '"';
I := I + 1;
end else if ((Copy(Buff,I,1) = '"') and (Copy(Buff,I+1,1)= ',')) then begin
I := I + 2;
ShowMessage(vShow);
vShow := '';
Break;
end else if ((Copy (Buff,I,1) = '"') and (vConut = I)) then begin
ShowMessage(vShow);
end else
vShow := vShow + Copy(Buff,I,1);
end;
end else if vStr = ',' then begin
vChar := ',';
Inc(I);
ShowMessage(vShow);
vShow := '';
end else if (vStr = '"') then begin
vNumber := 1;
while I < vConut do begin
if (Copy(Buff,I+1,1)) = '"' then begin
Inc(vNumber);
Inc(I);
end else
Break;
end;
vNumber := (vNumber div 2) - 1;
for n := 0 to vNumber do
vShow := vShow + '"';
Inc(I);
end else begin
vChar := Copy(Buff,I,1);
Inc(I);
vShow := vShow + vChar;
end;
end;
end;
end;
ShowMessage(vShow);
finally
fd.Free;
end;
end;