asp_databases thread: Outputting content fails if a comma is present
Message #1 by "Craig Flannigan" <ckf@k...> on Wed, 17 Oct 2001 10:05:32 +0100
|
|
Hi,
I've built a download option on our intranet which loops through a database
and outputs it into a CSV file.
That part is easy, and it works well. However, if there is a comma in one of
the fields, this is taken to be a field separator and it then throws it all
out of sync.
This problem is similar to when you're inserting into a database you use the
Replace command to stop single apostrophe, but how do you handle commas in
the text? I tried the Replace(objRST(1),",",,") but this just places two
fields instead.
Please help!
Many thanks
Craig.
Message #2 by Steve Carter <Steve.Carter@t...> on Wed, 17 Oct 2001 10:20:09 +0100
|
|
If you surround each value with quotes then commas will be ignored between
the quotes.
But then you need to escape your quotes, so instead of your current:
outString = outString & "," & fieldValue
try
outString = outString & ",""" & replace(fieldValue,"""","""""") & """"
so instead of
steve "lefty" carter,tradepartners,York, North Yorkshire, UK
you get
"steve ""lefty"" carter","tradepartners","York, North Yorkshire, UK"
> -----Original Message-----
> From: Craig Flannigan [mailto:ckf@k...]
> Sent: 17 October 2001 10:06
> To: ASP Databases
> Subject: [asp_databases] Outputting content fails if a comma
> is present
>
>
> Hi,
>
> I've built a download option on our intranet which loops
> through a database
> and outputs it into a CSV file.
>
> That part is easy, and it works well. However, if there is a
> comma in one of
> the fields, this is taken to be a field separator and it then
> throws it all
> out of sync.
>
> This problem is similar to when you're inserting into a
> database you use the
> Replace command to stop single apostrophe, but how do you
> handle commas in
> the text? I tried the Replace(objRST(1),",",,") but this just
> places two
> fields instead.
>
> Please help!
>
>
> Many thanks
> Craig.
Message #3 by "Craig Flannigan" <ckf@k...> on Wed, 17 Oct 2001 12:17:21 +0100
|
|
Thanks very much Steve.
Just what I needed.
Message #4 by "Tomm Matthis" <matthis@b...> on Wed, 17 Oct 2001 09:25:26 -0400
|
|
Surround all text fields with quotes in the output file.
-- Tomm
|