我想删除文件中不必要的逗号,代码如下:
const data: any = utils.sheet_to_csv(ws);
let blob = new Blob(['\ufeff' + data], { type: 'text;charset=utf-8;' });
let dwldLink = document.createElement("a");
let url = URL.createObjectURL(blob);
我从第一行得到低于输出:
,,,,, ,NTD00539,100000,01,Varsha,20180607
如何删除前5个逗号?
答案 0 :(得分:0)
您可以删除不必要的',',如下所示:
while (data.match(/^,/) != null) {
data = data.replace(/^,/, ""); //replace comma from firstplace
}
while (data.match(/,\s*$/) != null) {
data = data.replace(/,\s*$/, ""); //replace comma from lastplace
}
while (data.match(/,,/g) != undefined) {
data = data.replace(/,,/g, ','); console.log('count')//replace consecutive occurrence of comma
}