Yeah, I've had similar problems, especially with stuff exported from excell (which doesn't quote). Had worse problems with csv files containing multi line fields. One solution is that you load the csv file into something like word and replace each comma with "," and each new line ^l with "^l" then you just need to ammend the first and last character.

You could try this hidious procedure I wrote some time back:

Function CommaDelimToStringList(s : String; List : TStringList; Delim : string = ',') : boolean;
var
ts : string; //temp string
field : string;
ThePos : integer;
begin
List.Clear;
ts := s;
ThePos := pos(Delim, ts);
while ThePos <> 0 do
begin
field := Copy(ts, 1, ThePos - 1);
Delete(ts, 1, ThePos);
StrReplace('"', Field, '');
List.Add(TRIM(Field));
ThePos := pos(Delim, ts);
end;
StrReplace('"', ts, '');
List.Add(ts);
result := true;
end;


Alister

Robert martin wrote:
Hi all
I have been working with the CommaText method of a stringlist to import a csv file. One of my test files does not use double quotes around fields containing spaces, the CommaText method splits the field into multiple fields. I thought double quotes were only required around fields containing commas. Does anyone know which format is the 'Official' format. If the CommaText method does not function correctly I will right my own (unless anyone has other suggestions).
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to