There is a solution: replace all line breaks found between double-quotes with a temporary character and replace back this character with line breaks after a record has been parsed. They are again considered as end of records. Line breaks between double-quotes are not considered as part of the fields as they should be. Unfortunately, this will fall into the same trap as Excel. MsgBox, Field #%A_Index%:`n`n%A_LoopField% Loop, Read, %A_ScriptDir%\TheBeatles-Lyrics.txt We would have something like this: #NoEnv How can AutoHotKey help us? Let’s try with the "Loop, Parse, CSV" command. In that case, the line "She loves you, yeah, yeah, yeah" in the middle of the lyrics is interpreted as a record with four fields separated by the commas. For example, you will find multi-line fields in exports from Outlook or Google contacts where the "Notes" field includes line breaks.īut if we try to import these files in MS Excel, we have a problem because each end-of-line is interpreted at the end of a record. This is a valid CSV file: fields including line breaks are enclosed in double-quotes. Get Back,Let It Be,12,"Get back, get back. Nothing is real and nothing to get hungabout. Strawberry Fields Forever,Magical Mystery Tour,8,"Let me take you down, 'cos I'm going to Strawberry Fields. Ticket To Ride,Help!,7,"She's got a ticket to ri-hide, 1",4,"She loves you, yeah, yeah, yeahĮight Days A Week,Beatles For Sale,8,"Eight days a week
Strawberry Fields Forever,Magical Mystery Tour,8īut if we add a fourth field with the lyrics of these songs, then we have a multi-line field: Title,Album,Track,Lyrics
In most comma-separated-values (CSV) files, each record stands on its own line, with each field separated by a comma. Control fields order with the function ObjCSV_CSV2Collection.Reading and parsing a CSV file with multi-line fields (this post).
This tutorial will show you how to load and save CSV files with multi-line fields.