Read/write .csv where individual field contains a comma

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Read/write .csv where individual field contains a comma

Post by Warren » Mon Oct 23, 2017 1:59 pm

I just realized I've backed myself into a corner where I"m reading and writing from csv, but now that I've created 100 of the csv's, I realized a few of them have a field that contains a comma.

What's the best resolution?

Is there a convention like encasing the field in special characters like {"..."}, or force a different delimiter like a colon? Just looking to do whatever the standard solution is.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Read/write .csv where individual field contains a comma

Post by Marcus Tettmar » Tue Oct 24, 2017 11:09 am

With CSV you should put strings in quotes. Then you'd have no issue:

"this, string", 5, "blue"

That is three fields and CSV/Excel will cope. Without the quotes clearly Excel is going to treat it as 4 fields.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts