javascript 对 CSV 中的文本进行排序

标签 javascript replace

我的 Excel CSV 文件中有数据。这是格式。

"","","","","the useful data
"
"","","","","the useful data
"
"","","","","the useful data
"
"","","","","the useful data
and the rest
"

如何格式化此文本,使最后一列末尾有“并使其像这样。

"","","","","the useful data"
"","","","","the useful data"
"","","","","the useful data"
"","","","","the useful data and the rest"

我为此使用 JavaScript。

最佳答案

var myCSVContent = ... // your csv here
myCSVContent
    // removes line breaks within value and add whitespace
    .replace(/((?:\\")|[^"])\n([^"])/g, "$1 $2")   
    // removes unwanted line breaks
    .replace(/\n(["\w])([^"]|$)/g, "$1$2") 

关于javascript 对 CSV 中的文本进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35410591/

相关文章:

javascript - 字符串替换某些匹配组,而不是整个匹配

javascript - 如何在javascript中转义^字符?

c++ - 要求编辑文本,文本格式

javascript - 单个 Electron createWindow() 实例变量

javascript - 如果 id 与 php 中的 session id 不相关,如何重定向页面

JavaScript : Printing Dynamic value/data

javascript - jQuery : append or replace automatic?

javascript - 如何在可点击元素内制作按钮?

javascript - 如何在 Angular Material 中的 md-backdrop 后面接收 ng-click 事件

regex - Sublime Text 2 RegEx 用 n+1 替换 n