Why does the Split object surround everything with quotation marks?
Posted: 2019-12-23 07:03:25
Good people,
I'm working on a macro to take data from one CSV file, reformat it, and export it as another CSV file. And learning how much I didn't know about the macro language while I'm at it.
To load the data from the first CSV file, I'm using the .split command:
This will take a line of data delimited by commas and turns it into a set of items in $TheFields
The relevant code isn't very good, but I'll post it anyway so you can see the context:
I'm sure people can tell me a better way than the Copy and Read clipboard steps (and I will accept help
), but that's merely inefficient. What is not working is the .split step. It appears that it is correctly splitting the fields, but then putting quote marks around them. So, for example, if I started with this record in $TempDoc,
Field1,Field2,"Field 3. with quotes",Field 4
What I get out in $FinalDoc is
"Field1","Field2",""Field 3. with quotes"","Field 4"
I could theoretically live with the quotes around Field1, Field2, and Field 4 -- it's valid CSV -- but not the excess quotes around Field 3. I could surely figure out some replace commands to fix this, but that strikes me as non-optimal. Is there a way to make the split command NOT put quotes around the fields? Or is this just a quirk of using the Type command to list $TheFields?
I'm working on a macro to take data from one CSV file, reformat it, and export it as another CSV file. And learning how much I didn't know about the macro language while I'm at it.

To load the data from the first CSV file, I'm using the .split command:
Code: Select all
$TheFields = $MyCurrentRecord.split(',')
The relevant code isn't very good, but I'll post it anyway so you can see the context:
Code: Select all
Document.setActive $TempDoc
Select Document Start # Make sure we start splitting at the beginning of the document!
# Now start running through the paragraphs
While Select Next Paragraph
# There IS a next paragraph to select
Copy
$MyCurrentRecord = Read Clipboard
$TheFields = $MyCurrentRecord.split(',')
Document.setActive $FinalDoc
Type text $TheFields
Type newline
Document.setActive $TempDoc
End

Field1,Field2,"Field 3. with quotes",Field 4
What I get out in $FinalDoc is
"Field1","Field2",""Field 3. with quotes"","Field 4"
I could theoretically live with the quotes around Field1, Field2, and Field 4 -- it's valid CSV -- but not the excess quotes around Field 3. I could surely figure out some replace commands to fix this, but that strikes me as non-optimal. Is there a way to make the split command NOT put quotes around the fields? Or is this just a quirk of using the Type command to list $TheFields?