Reputation: 11
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);
Upvotes: 0
Views: 456
Reputation: 39408
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);
Upvotes: 1