CSV files filed containing comma itself
Hi..
I am using JavaScript..
I have CSV file and I have fields like ID, Name, Value..
In name field many times value is like::
"America's Greatest Offer, get FREE"...
So here comma coming and its separating and I am not getting proper data in table.
Can i replace by anything so can get data as it is...
Bcoz i want the same name in DB. Please Reply...
[385 byte] By [
tejalm] at [2007-11-19 20:16:25]

# 1 Re: CSV files filed containing comma itself
Well, JavaScript is a client-side language and cannot interact with a database. What language are you using for the database and can you please post your source code?
# 2 Re: CSV files filed containing comma itself
Hi,
I am using JavaScript to get an arrays.
Right now dont think about database. That is doing by VBScript. Please give me solution of this.
Code::
For (j=0 ; j < i ; j++)
{
strOut = strOut + arrId[j] + "," + arrName[j] + "," + arrUpdate[j] + "," + arr_Desc[j] + "," + arrIncent[j] + "," + arrEDate[j] + "," + "\n" ;
}
formname.textarea.value = strout;
And in textarea will get CSV data.
My name field containing comma so I am not getting proper data.
I am having one solution for that:
In for loop at the beginning I will include this...
var name = arr_Name[i];
name = +name +;
So it will give me proper string with comma.
But now problem is there that name containing also.
Take one example ::
Name = hi its me, how are you ? say hi
So it will create problem again. I cant replace with any other character. Bcoz I want name field as it is with ' and " also.
So please give me solution of this.
# 3 Re: CSV files filed containing comma itself
I am using JavaScript to get an arrays.
Right now dont think about database. That is doing by VBScript. Please give me solution of this.
Then don't give all the extra information to start with. When posting, only give information relevant to the problem at hand that way you don't have to worry about confusion like we experienced.
Now to the solution. In just about any scripting language, JavaScript is one of them, you echo double or single quotes by preceeding it with a backslash. This will solve your problem. Below is an example.
<script language="JavaScript">
alert("\"Hi!\"");
</script>
# 4 Re: CSV files filed containing comma itself
I have used \" already, but there isn't any effect of that replacement.
Bcoz name is like :: "example of quotes.. say "hi"..." So bcoz of starting and ending quotes its not giving proper output..
After getting an array I am adding " to name field so if any comma will come in name field then it will not separate by comma.
But now coming 4 times in field so problem is again there..
Any Solution ?