WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: JTaylor on January 20, 2021, 02:34:40 PM

Title: MapCreate() Error
Post by: JTaylor on January 20, 2021, 02:34:40 PM
Is it expected that a quote in a Map value would not be allowed?   Not seeing it in the Help.   

Jim

Code (winbatch) Select

Pairs = 'Apples':@TAB:'HELLO':@CR:'Oranges':@TAB:'GOODBYE':@CR:'Pears':@TAB:'WOR"LD'

Fruit = MapCreate(Pairs,@TAB,@CR)
Foreach key in Fruit

   Message("YO",Fruit[key])

Next


Title: Re: MapCreate() Error
Post by: td on January 20, 2021, 02:54:16 PM
It is a bit gnarly. This will work:

Pairs = 'Apples':@TAB:'HELLO':@CR:'Oranges':@TAB:'GOODBYE':@CR:'Pears':@TAB:'"WOR""LD"'

Basically, double quotes are considered content delimiters used to allow the inclusion of list pair delimiters. So they need to be escaped and contained within double quotes when being used as field content. Probably need to add that to the MapCreate topic.
Title: Re: MapCreate() Error
Post by: JTaylor on January 20, 2021, 03:33:11 PM
Hmmmmmmm...this complicates how I was using it.   Will have to ponder this one.

Jim
Title: Re: MapCreate() Error
Post by: td on January 20, 2021, 03:46:28 PM
It is more or less CSV file like.
Title: Re: MapCreate() Error
Post by: kdmoyers on January 21, 2021, 07:24:06 AM
I ran into this too.  Fortunately, my use-case allowed me to simply strip the double quotes out of the data before putting into the map. 

The note in the help article would be helpful especially since when you explicitly set the two main delimiters, you figure they are the only chars you have to watch for. 

Or perhaps have winbatch handle doubling up the quote chars for you? not sure that would work.  very tricky...
Title: Re: MapCreate() Error
Post by: JTaylor on January 21, 2021, 07:33:58 AM
I was able to make it work but agreed on the note.   I assumed all would be good since I was defining the delimiters.

Jim
Title: Re: MapCreate() Error
Post by: td on January 21, 2021, 07:44:07 AM
Quote from: kdmoyers on January 21, 2021, 07:24:06 AM
...
Or perhaps have winbatch handle doubling up the quote chars for you? not sure that would work.  very tricky...

It is dammed if you do and dammed if you don't situation. There is no way to know if a stray quote is intentional or a mistake.  It is best to maintain a rule based on a known WinBatch standard.
Title: Re: MapCreate() Error
Post by: kdmoyers on January 21, 2021, 07:50:34 AM
I see what you mean.  Yeah, just the warning note in the helps.