I am parsing the csv file in javascript using the below logic. The logic works correctly in firefox browser but on chrome browser, the output is different.
var r = new FileReader();
r.onload = function (e) {
contents = e.target.result;
$scope.$apply(function () {
$scope.fileReader = contents;
contents = contents.replace(/\r\n+/g, ",");
reqObj.names = contents.split(",");
defer.resolve("Succesfully executed");
});
};
r.readAsText(file);
Output in Firefox : names: ["pradeep", "naveen", "kiran"] Output in Chrome : names: ["pradeep\nnaveen\nkiran"]
Please let me know where I am going wrong.
/\r\n+/gmean in javascript.replace(/\r\n+/g, ",")replaces a CR followed with 1+ LF symbols with a comma multiple times. I guess it should have been written as.replace(/(?:\r?\n)+/g, ",")