"Index of out array bounds" error with ampersand.

  • Thread starter Thread starter writebrent
  • Start date Start date
W

writebrent

I wrote a little interface for users to post data to a website. On
their local machines, it produces CSV from an Excel spreadsheet, then
posts it to the site. In some cases, the CSV will contain ampersands.
For example,

abc,American & British Company,1,4.34,5
ded,Dog Eat Dog,2,6.3,5.766

The code on the site is pretty standard: it loops through an array of
lines from the CSV split on line ends, and then loops through another
array of data created from splitting each line on the comma.

Easy.

But, for some reason, when it encounters "&", the code breaks down and
ignore the rest of the line. So, I get an "Index out of bounds" error.

To fix it, I stripped the "&" character, and all runs well. But I'd
rather keep it in. If you've any hints how to fix this (simple?) error,
I'd appreciate your help.

Thanks.

--Brent
 
I wrote a little interface for users to post data to a website. [snip]
But, for some reason, when it encounters "&", the code breaks down and
ignore the rest of the line. So, I get an "Index out of bounds" error. [snip]
If you've any hints how to fix this (simple?) error,
I'd appreciate your help.

It's hard to help if you don't provide a compiling code sample that
demonstrates the problem.

-- Barry
 
Brent,
As Barry has already indicated, unless you can provide a "Short but
complete" code sample, it's really a shot in the dard to help you. I will say
this; standard CSV data not only has comma delimiters, it also has double
quote marks on either side of each value. This permits having a line such as
"John & John, Attorneys".
and not having it blow up in your face.
Peter
 
Peter said:
Brent,
As Barry has already indicated, unless you can provide a "Short but
complete" code sample, it's really a shot in the dard to help you. I will say
this; standard CSV data not only has comma delimiters, it also has double
quote marks on either side of each value.

Some do, some don't...

The CSV file format is sadly lacking any standard, so the format varies.
Some comma separated files are actually not separated by commas at all,
but semicolons. Some values are surrounded by quotes, some aren't. The
only values really needing quotes are the ones containing the separator
or quotes.
 
Back
Top