0

I want to remove unnecessary commas in file, with below code:

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);

I am getting below output from 1st line:

,,,,,       ,NTD00539,100000,01,Varsha,20180607   

How to remove first 5 commas?

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

You can remove the unneccessary ',' as shown below:

    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 
    }
Rak2018
  • 935
  • 6
  • 16