viewpoint-particle

Author Topic: MapCreate() Error  (Read 195 times)

JTaylor

  • Pundit
  • *****
  • Posts: 1655
    • Data & Stuff Inc.
MapCreate() Error
« 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
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

  • Tech Support
  • *****
  • Posts: 3701
    • WinBatch
Re: MapCreate() Error
« Reply #1 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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

  • Pundit
  • *****
  • Posts: 1655
    • Data & Stuff Inc.
Re: MapCreate() Error
« Reply #2 on: January 20, 2021, 03:33:11 pm »
Hmmmmmmm...this complicates how I was using it.   Will have to ponder this one.

Jim

td

  • Tech Support
  • *****
  • Posts: 3701
    • WinBatch
Re: MapCreate() Error
« Reply #3 on: January 20, 2021, 03:46:28 pm »
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

  • Sr. Member
  • ****
  • Posts: 408
Re: MapCreate() Error
« Reply #4 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...
The mind is everything; What you think, you become.

JTaylor

  • Pundit
  • *****
  • Posts: 1655
    • Data & Stuff Inc.
Re: MapCreate() Error
« Reply #5 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

td

  • Tech Support
  • *****
  • Posts: 3701
    • WinBatch
Re: MapCreate() Error
« Reply #6 on: January 21, 2021, 07:44:07 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

  • Sr. Member
  • ****
  • Posts: 408
Re: MapCreate() Error
« Reply #7 on: January 21, 2021, 07:50:34 am »
I see what you mean.  Yeah, just the warning note in the helps.
The mind is everything; What you think, you become.