Jump to content

Parse CSV crash


Go to solution Solved by czardas,

Recommended Posts

but you are using single quotes to enclose?  so this string

 

$sString = '"1", '''''''''', hello world' & @LF & '(*), "1,2,3,4,5", "@", "4TH"' & @LF & '"2", """""""""", hello 2 world , "4TH" , "5TH"' & @LF

 

You would get half of the single quotes and all of the double quotes.  I didnt gather what the desired outcome in that instance would be.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

We have fields enclosed in double quotes:

,"field" becomes ==> field

;

You can have double quotes within fields enclosed in double quotes:

,"""field""" becomes ==> "field"
,"""""" becomes ==> ""

:

Fields can also contain line breaks:

,"A
B"

becomes ==>

A
B
Edited by czardas
Link to comment
Share on other sites

Ah yes,  The csv rules.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

FYI, This is the line the Parse CSV chokes on:

    Local $aREgex = StringRegExp($sFile, $sPattern, 3)
 
I hear you all talking about escaping double quotes, but why would it only fail on one of the two records? Is the content of the record too long?
 
@UEZ If you open the file in notepad++ and do a regex replace on n you can see the two records as single lines each.
 
@BrewManNH
I think you might be right with the stack overflow... Is there a way to tell? Just delete some of the text?
 
 
The only real difference I can see is the the column in the first record is 9173 characters and the second is 4091 (ignoring CRs and LFs)
 
 
EDIT:
This did work:
Local $aArray = _CSVSplit(FileRead($filename),",")
_ArrayDisplay($aArray)
Edited by Jewtus
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...