0

In CSV file that export from mysql, a few data has linebreak

This
is
Sunday

into

This is Sunday

How do I replace those linebreak into "\n" character which I can parse at later time. It seem the code below does not replace correcly. Parse

result = result.replace(/[\\r\\n]/g, "\\n");

Next, to split into array

var splitRegExp:RegExp = /\r*\n+|\n*\r+/gm;
var lines:Array = result.split(splitRegExp);
Proyb2
  • 11
  • 1
  • You can avoid the problem by doing a better export. See [1119312](http://stackoverflow.com/questions/1119312/mysql-export-into-outfile-csv-escaping-chars) – ceving May 04 '11 at 08:37

1 Answers1

1

In Flex/ActionScript the '\n' character is already a line break. You don't need to replace it w/ anything. I've used something like this to turn line breaks into a comma separated list:

var lineFeedRegEx : RegExp = new RegExp('\n|\r|(\r\n)' ,'ig');
results = results.replace(lineFeedRegEx , ',');  

It should support all possible iterations of carriage return (\r) / line feed (\n). From there you could be able to split it into an array:

var lines:Array = result.split(',');

However, I Bet you can cut out the middleman completely:

var lineFeedRegEx : RegExp = new RegExp('\n|\r|(\r\n)' ,'ig');
var lines:Array = result.split(lineFeedRegEx);
JeffryHouser
  • 39,401
  • 4
  • 38
  • 59