Hmm, Remove line break / endings in text field

I have a text field that will occasionally have line endings. Like the example below:

Some data has been entered
More data entered
Look even more

And when I go to parse it out to a .csv for use, I get weird breaks in my csv file. ( See Image Below )

How do I remove the line breaks in the text field when I am reading it into the array for exporting out?

It would help to see one of those CSVs to understand how it was encoded.

CSVs can be like:

ABC,Hello,123.45

or

"ABC","Hello",123.45

a line break should be

"line\nbreak",123

because 99% of the parsers will fail at

"line
break",123

Perhaps sanitize your inputs using String.ReplaceLineEndings(““)?

Norman Palardy has CSVParser available on GitHub. It correctly (as far as I can recall) handles reading and writing CSV including escaping characters that cannot be supported by the CSV format, like line endings.

2 Likes

I had similar problems recently. Using the String.ReplaseLineEndings function (as suggested by Christian Wheel) worked perfectly for me. You just have to decide what to use as a replacement (empty string, space, “\n” or something else, in my project I used a pipe “|”).

I use Norm’s parser, but there’s a potential gotcha to be aware of: it uses BinaryStream, which has no encoding, so in some cases you may need to use DefineEncoding on the values passed to the HandleLine method.

I once subclassed it to convert CSV to JSON and the output JSON didn’t like nil encoding.

1 Like

Here is a sample of the csv I created from my XOJO program

188,89588,Tank 495Gal,1335 S Main Street - Tank,83,70%,0,0,,,2026-02-09,10:57:30,C
189,257838,54742,1349 S Main Street #1,4328,4328,10,0,Locked Off,Yellow tag S--441620. 
locked off for a while. Locked off due to - House Empty,2026-02-09,10:58:38,C
190,302205,54750,1349 S Main Street #3,16914,16922,10,80,,,2026-02-09,10:59:14,C
191,1514278,54726,1349 S Main Street #2,26696,26788,10,920,,Meter is not locked off or lock has been removed by tech/driver.,2026-02-09,11:00:01,C
192,994148,60765,10633 N Airport Road,20891,20961,10,700,,Broken security seal - REPLACE METER
Replace meter

,2026-02-09,11:29:06,C
193,336825,60773,10635 N Airport Road,6910,6912,100,200,,,2026-02-09,11:29:17,C
194,11908,Tank 250Gal,10633 N Airport Road - Tank,55,43%,0,0,,,2026-02-09,11:29:35,C
195,M714110,94128,22945 Hudson Road Unit B,3267,3275,100,800,,,2026-02-09,11:34:42,C
196,M098176,125486,22945 Hudson Road Unit A,1643,1643,100,0,Locked Off,Red tag . 
no tag?. Locked off due to - Delinquent Payment,2026-02-09,11:35:36,C
197,010360,Tank 499Gal,22941 Hudson Road - Tank,78,75%,0,0,,,2026-02-09,11:36:05,C

Line 189 is split so that a portion is below, over the top of line 190

Line 192 is split so that is covers three lines between line 192 and 193.

Same with line 196, the data that is supposed to be on that line is on the bottom between 196 and 197.

Lines 193, 194, 195, 196 are formatted correctly.

Here is how the array is constructed

// Build the array with the record set and a comma to separate values...
sOutput.AddRow rsData.Column( "rNum").StringValue + "," + rsData.Column( "unitSerNum").StringValue + "," + rsData.Column( "acctNum").StringValue + "," _
+ sAddress + "," + rsData.Column( "lastRead").StringValue + "," + rsData.Column( "currRead").StringValue + "," + rsData.Column( "multiplier").StringValue _
+ "," + rsData.Column( "useCalc").StringValue + "," + rsData.Column( "status").StringValue + "," + rsData.Column( "notes").StringValue + "," _
+ rsData.Column( "readDate").StringValue + "," + rsData.Column( "readTime").StringValue + "," + rsData.Column( "statusOf").StringValue

The RowSet rsData, is pulled from a table that was loaded with the data earlier in the day, week or month. The issue is with rsData.Column( “notes”).StringValue because this is where the line breaks, carriage returns or what have you, are stored and are causing the output error.

This worked. Thank you… doing this stuff tired is not very smart on my part… thank you…

This is very error prone. You need escaping encoding; or line breaks, or even commas (written or numbers in locales using commas) in your texts, will break things.

2 Likes