MapCreate() Error

Started by JTaylor, January 20, 2021, 02:34:40 PM

Previous topic - Next topic

JTaylor

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



td

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Hmmmmmmm...this complicates how I was using it.   Will have to ponder this one.

Jim

td

It is more or less CSV file like.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

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...
The mind is everything; What you think, you become.

JTaylor

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

td

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

I see what you mean.  Yeah, just the warning note in the helps.
The mind is everything; What you think, you become.