Re: [U2] CSV to Array

2012-08-20 Thread Keith Johnson [DATACOM]
No-one seems to have done it, but here's my version of the code.

It's strange, I don't have a problem with CONTINUE and I don't even mind
IF SOMETHING ELSE THIS = THAT
which a lot of people really hate, but I just HAD to reverse the IF/CASE 
statement order.

SUBROUTINE REXY(RECORD,TEXT)
*
 HERE = 0
 QUOTED = @FALSE
 RECORD = ''
 LOOP
HERE += 1
C = TEXT[HERE,1]
 UNTIL C EQ ''
BEGIN CASE
   CASE QUOTED AND TEXT[HERE,2] EQ '""'
  HERE += 1
   CASE C EQ '"'
  QUOTED = NOT(QUOTED)
  C = ''
   CASE C EQ ',' AND NOT QUOTED
  C = @FM
END CASE
RECORD := C
 REPEAT
 RETURN
  END

Regards, Keith

PS: Remember Messrs Stout and Chapman - "Simplicate and add more lightness"

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


Re: [U2] CSV to Array

2012-08-16 Thread David Wolverton
Oh that is interesting ... will have to give that a run!  Thanks Wol!

-Original Message-
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Wols Lists
Sent: Thursday, August 16, 2012 7:40 AM
To: u2-users@listserver.u2ug.org
Subject: Re: [U2] CSV to Array

On 15/08/12 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)
> 
Given that you're parsing on a delimiter, actually the best tool here is
probably MATPARSE! You need two dimensions, however.

Something like

DIM ARRAY(100,2)

MATPARSE STRING USING ',"'

Until I actually played with it, I didn't realise it put text into column 1,
and delimiters into column 2. Which makes it easy to ding through. If say
you have a comma followed by two double quotes, it will put the comma in
column 2, a blank in column 1, and then both double quotes in the next
element in column 2. I was actually parsing a maths statement, but it was so
easy ...

Cheers,
Wol
___
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


Re: [U2] CSV to Array

2012-08-16 Thread David Wolverton
And I missed the whole 'Escaping Double Quotes' thread -- so this is already
covered... Skip this post!!  ;-)

-Original Message-
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of David Wolverton 
Sent: Thursday, August 16, 2012 5:42 PM
To: 'U2 Users List'
Subject: Re: [U2] CSV to Array

You can't have 

"3/4" Bolts"  in the data stream -- that would not work.  So that means the
embedded " has to be 'escaped' - usually by a \..

So you'd have "3/4\" Bolts" or the like ... right?

In that case, you'd want to 'swap' out the \" for some other 'hold
character'  first -- like &&DQOUTE&& And Then swap out the  'remaining'  '"'
out as listed.

I did forget that!

At the very end, you 're-swap'  &&DQUOTE&& for '"'

DW

-Original Message-
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Mecki Foerthmann
Sent: Thursday, August 16, 2012 2:26 AM
To: u2-users@listserver.u2ug.org
Subject: Re: [U2] CSV to Array

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
>END ELSE
>  DATAROW = NEWSTRING
>      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

___
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


Re: [U2] CSV to Array

2012-08-16 Thread David Wolverton
You can't have 

"3/4" Bolts"  in the data stream -- that would not work.  So that means the
embedded " has to be 'escaped' - usually by a \..

So you'd have "3/4\" Bolts" or the like ... right?

In that case, you'd want to 'swap' out the \" for some other 'hold
character'  first -- like &&DQOUTE&&
And Then swap out the  'remaining'  '"' out as listed.

I did forget that!

At the very end, you 're-swap'  &&DQUOTE&& for '"'

DW

-Original Message-
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Mecki Foerthmann
Sent: Thursday, August 16, 2012 2:26 AM
To: u2-users@listserver.u2ug.org
Subject: Re: [U2] CSV to Array

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
>END ELSE
>  DATAROW = NEWSTRING
>  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

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


Re: [U2] CSV to Array

2012-08-16 Thread Rex Gozar
It is tempting to use SWAP or CONVERT statements when parsing CSV, but
they never handle all the possible cases correctly.  You have to look
at each character and keep track of state.

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


Re: [U2] CSV to Array

2012-08-16 Thread Wjhonson
Thanks for the support.

As I was working my way through the code I posted I noticed that if you 
embedded in the quote is a check to see if the character we're on *and* the 
next character are both double quotes.

But if that's true, than the initial check for a double quote to even get 
*into* that section is redundant.  You can't have two double quotes in a row if 
you don't start with a double quote to begin.

Of course the opposite case is true, you could start with a double quote and no 
have two double quotes in a row.  Perhaps tomorrow I will post the code with 
which I ended up.  Written as a subroutine, then maybe someone can break it.

Will

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


Re: [U2] CSV to Array

2012-08-16 Thread George Gallen
Tab seems to be the default character of choice of mysql/mssql output as well.
As well, Excel seems to like "" to mean ", but other programs seem to want \"
So tab works good here as well. 

But I still use comma when exporting to clients, unless they ask for tabs. 

-Original Message-
From: u2-users-boun...@listserver.u2ug.org 
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Charlie Noah
Sent: Thursday, August 16, 2012 5:26 AM
To: U2 Users List
Subject: Re: [U2] CSV to Array

I have double quotes in my product descriptions, and yes, they are a 
pain! I also prepare Google Shopping data feeds for clients who don't 
want to fight it themselves. This is why I prefer tab delimited with no 
surround character. Unless you have tabs in your actual data, no 
problems. Technically, it's not csv anymore, but who cares?

Charlie Noah

Tiny Bear's Wild Bird Store
"Everything For The Backyard Bird Enthusiast, Except For The Birds"
http://www.TinyBearWildBirdStore.com
Toll Free: 1-855-TinyBear (855-846-9232)

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


Re: [U2] CSV to Array

2012-08-16 Thread Michael Martin


-Original Message-
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Dianne
Ackerman
Sent: Thursday, August 16, 2012 7:52 AM
To: U2 Users List
Subject: Re: [U2] CSV to Array

I actually enjoy reading wjhonson's "puzzle" posts with code examples,
etc.  Maybe they can be flagged in the header so those of you who don't
want to read them can just skip them.
-Dianne

On 8/15/2012 5:49 PM, Tony Gravagno wrote:
> Anyone getting paid to play guessing games? Dude, get to the point. If

> this were presented as "I need help" I think many people would jump to

> help. But presenting this as a Mensa challenge is just wasting 
> people's time.
> T
>
> Wjhonson wrote:
>   > 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 ?
> ___

___
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


Re: [U2] CSV to Array

2012-08-16 Thread Dave Laansma


Sincerely,
David Laansma
IT Manager
Hubbard Supply Co.
Direct: 810-342-7143
Office: 810-234-8681
Fax: 810-234-6142
www.hubbardsupply.com
"Delivering Products, Services and Innovative Solutions"

-Original Message-
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Dianne
Ackerman
Sent: Thursday, August 16, 2012 8:52 AM
To: U2 Users List
Subject: Re: [U2] CSV to Array

I actually enjoy reading wjhonson's "puzzle" posts with code examples,
etc.  Maybe they can be flagged in the header so those of you who don't
want to read them can just skip them.
-Dianne

On 8/15/2012 5:49 PM, Tony Gravagno wrote:
> Anyone getting paid to play guessing games? Dude, get to the point. If

> this were presented as "I need help" I think many people would jump to

> help. But presenting this as a Mensa challenge is just wasting 
> people's time.
> T
>
> Wjhonson wrote:
>   > 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 ?
> ___

___
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


Re: [U2] CSV to Array

2012-08-16 Thread Dianne Ackerman
I actually enjoy reading wjhonson's "puzzle" posts with code examples, 
etc.  Maybe they can be flagged in the header so those of you who don't 
want to read them can just skip them.

-Dianne

On 8/15/2012 5:49 PM, Tony Gravagno wrote:

Anyone getting paid to play guessing games? Dude, get to the point. If
this were presented as "I need help" I think many people would jump to
help. But presenting this as a Mensa challenge is just wasting
people's time.
T

Wjhonson wrote:
  > 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 ?

___


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


Re: [U2] CSV to Array

2012-08-16 Thread Wols Lists
On 15/08/12 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)
> 
Given that you're parsing on a delimiter, actually the best tool here is
probably MATPARSE! You need two dimensions, however.

Something like

DIM ARRAY(100,2)

MATPARSE STRING USING ',"'

Until I actually played with it, I didn't realise it put text into
column 1, and delimiters into column 2. Which makes it easy to ding
through. If say you have a comma followed by two double quotes, it will
put the comma in column 2, a blank in column 1, and then both double
quotes in the next element in column 2. I was actually parsing a maths
statement, but it was so easy ...

Cheers,
Wol
___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users


Re: [U2] CSV to Array

2012-08-16 Thread Charlie Noah
I have double quotes in my product descriptions, and yes, they are a 
pain! I also prepare Google Shopping data feeds for clients who don't 
want to fight it themselves. This is why I prefer tab delimited with no 
surround character. Unless you have tabs in your actual data, no 
problems. Technically, it's not csv anymore, but who cares?


Charlie Noah

Tiny Bear's Wild Bird Store
"Everything For The Backyard Bird Enthusiast, Except For The Birds"
http://www.TinyBearWildBirdStore.com
Toll Free: 1-855-TinyBear (855-846-9232)


On 08-16-2012 2:25 AM, Mecki Foerthmann wrote:
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
   END ELSE
 DATAROW = NEWSTRING
 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


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


Re: [U2] CSV to Array

2012-08-16 Thread Mecki Foerthmann
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
   END ELSE
 DATAROW = NEWSTRING
 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


Re: [U2] CSV to Array

2012-08-15 Thread David Wolverton
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
  END ELSE
DATAROW = NEWSTRING
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


Re: [U2] CSV to Array

2012-08-15 Thread larryh
This thread is CLOSED.  Take it offline.

Larry Hiscock
Moderator


>
> No one is forcing you to respond Phil.
> I posted some interesting code and asked for comments.
>
> The comments so far are just uncalled for abuse.
> You should be banned from this list.
>
>
> -Original Message-
> From: Phil Walker 
> To: U2 Users List 
> Sent: Wed, Aug 15, 2012 3:02 pm
> Subject: Re: [U2] CSV to Array
>
>
> At risk of starting a flame war, I agree with Tony. I need to tune my
> email
> rules better.
>
>> -Original Message-
>> From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users-
>> boun...@listserver.u2ug.org] On Behalf Of Wjhonson
>> Sent: 16 August 2012 9:58 a.m.
>> To: u2-users@listserver.u2ug.org
>> Subject: Re: [U2] CSV to Array
>>
>>
>> There's no point in being abusive Tony.  No one appreciates it.
>>
>>
>> -Original Message-----
>> From: Tony Gravagno <3xk547...@sneakemail.com>
>> To: u2-users 
>> Sent: Wed, Aug 15, 2012 2:50 pm
>> Subject: Re: [U2] CSV to Array
>>
>>
>> Anyone getting paid to play guessing games? Dude, get to the point. If
>> this
>> were presented as "I need help" I think many people would jump to help.
>> But presenting this as a Mensa challenge is just wasting people's time.
>> T
>>
>> Wjhonson wrote:
>>  > 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 ?
>>
>> ___
>> 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
>
>
> ___
> 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


Re: [U2] CSV to Array

2012-08-15 Thread Wjhonson

No one is forcing you to respond Phil.
I posted some interesting code and asked for comments.

The comments so far are just uncalled for abuse.
You should be banned from this list.


-Original Message-
From: Phil Walker 
To: U2 Users List 
Sent: Wed, Aug 15, 2012 3:02 pm
Subject: Re: [U2] CSV to Array


At risk of starting a flame war, I agree with Tony. I need to tune my email 
rules better.

> -Original Message-
> From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users-
> boun...@listserver.u2ug.org] On Behalf Of Wjhonson
> Sent: 16 August 2012 9:58 a.m.
> To: u2-users@listserver.u2ug.org
> Subject: Re: [U2] CSV to Array
> 
> 
> There's no point in being abusive Tony.  No one appreciates it.
> 
> 
> -Original Message-
> From: Tony Gravagno <3xk547...@sneakemail.com>
> To: u2-users 
> Sent: Wed, Aug 15, 2012 2:50 pm
> Subject: Re: [U2] CSV to Array
> 
> 
> Anyone getting paid to play guessing games? Dude, get to the point. If this
> were presented as "I need help" I think many people would jump to help.
> But presenting this as a Mensa challenge is just wasting people's time.
> T
> 
> Wjhonson wrote:
>  > 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 ?
> 
> ___
> 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

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


Re: [U2] CSV to Array

2012-08-15 Thread Phil Walker
At risk of starting a flame war, I agree with Tony. I need to tune my email 
rules better.

> -Original Message-
> From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users-
> boun...@listserver.u2ug.org] On Behalf Of Wjhonson
> Sent: 16 August 2012 9:58 a.m.
> To: u2-users@listserver.u2ug.org
> Subject: Re: [U2] CSV to Array
> 
> 
> There's no point in being abusive Tony.  No one appreciates it.
> 
> 
> -Original Message-
> From: Tony Gravagno <3xk547...@sneakemail.com>
> To: u2-users 
> Sent: Wed, Aug 15, 2012 2:50 pm
> Subject: Re: [U2] CSV to Array
> 
> 
> Anyone getting paid to play guessing games? Dude, get to the point. If this
> were presented as "I need help" I think many people would jump to help.
> But presenting this as a Mensa challenge is just wasting people's time.
> T
> 
> Wjhonson wrote:
>  > 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 ?
> 
> ___
> 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


Re: [U2] CSV to Array

2012-08-15 Thread Wjhonson

There's no point in being abusive Tony.  No one appreciates it.


-Original Message-
From: Tony Gravagno <3xk547...@sneakemail.com>
To: u2-users 
Sent: Wed, Aug 15, 2012 2:50 pm
Subject: Re: [U2] CSV to Array


Anyone getting paid to play guessing games? Dude, get to the point. If
this were presented as "I need help" I think many people would jump to
help. But presenting this as a Mensa challenge is just wasting
people's time.
T

Wjhonson wrote:
 > 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 ?

___
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


Re: [U2] CSV to Array

2012-08-15 Thread Tony Gravagno
Anyone getting paid to play guessing games? Dude, get to the point. If
this were presented as "I need help" I think many people would jump to
help. But presenting this as a Mensa challenge is just wasting
people's time.
T

Wjhonson wrote:
 > 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 ?

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


[U2] CSV to Array

2012-08-15 Thread Wjhonson

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