The moment you start working in the engineering or manufacturing industry where it is not uncommon to have double quotes embedded in a field (i.e 5 1/4" Steel Bar) your code will bite you.


On 15/08/2012 23:24, David Wolverton wrote:
I've done this in the past by doing this:

SWAP DQUOTE WITH @AM

Now, in theory, every EVEN attribute is a 'quoted' string - don't touch the
commas....
Every ODD attribute is a 'non-quoted' string...

Double check me here in case I've lost it... but this should work ... seems
this would be faster as well on larger records.  Only thing you'd have to
test for -- if the first character is a doublequote, we will have a blank
first attribute and should not -- but that could be tested in the END ELSE
section (IF XXX = 1 THEN IF DATASTRING[1,1] = 1 THEN CONTINUE)

DATASTRING = 'A,B,"C,D",E,F,"G,H,I",J,K,L
NEWSTRING = ""
SWAP '"' WITH @AM IN DATASTRING
AMCNT = DCOUNT(DATASTRING,@AM)
FOR XXX  =  1 TO AMCNT
   IF MOD(AMCNT,2) = 0 THEN
     NEWSTRING  := @AM: DATASTRING<XXX>
   END ELSE
     DATAROW = NEWSTRING<XXX>
     SWAP ',' WITH @AM IN DATAROW
     NEWSTRING := @AM:DATAROW
     NEWSTRING<-1>  = DATAROW
   END
NEXT XXX


-----Original Message-----
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Wjhonson
Sent: Wednesday, August 15, 2012 4:11 PM
To: u2-users@listserver.u2ug.org
Subject: [U2] CSV to Array


Rex Gozar uploaded this code, and someone (perhaps him) corrected it, but
there's a redundancy here.  I'm trying to fix it, in my own version, mostly
perhaps I *hate* the CONTINUE, but the logic is a bit convoluted eh?  Anyone
spot the redundancy ?

       EQU COMMA TO ','
       EQU DQ TO '"'
       BUFFER = TEXT
       BUFPTR = 0
       CPTR = 0
       QUOTESW = @FALSE
       LOOP
          CPTR += 1
          C = BUFFER[CPTR,1]
       WHILE (C NE "") DO
          IF (DQ EQ C) THEN
             IF (QUOTESW) AND (DQ:DQ EQ BUFFER[CPTR,2]) THEN
                CPTR += 1
             END ELSE
                QUOTESW = NOT(QUOTESW)
                CONTINUE
             END
          END
          IF (COMMA EQ C) AND NOT(QUOTESW) THEN
             C = @FM
          END
          BUFPTR += 1
          BUFFER[BUFPTR,1] = C
       REPEAT
       RECORD = BUFFER[1,BUFPTR]
       RETURN
    END

_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users


_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to