0

I've made a table with AngularJS with data that I'm parsing from an CSV file.
I'm using Papa.Parse for this.

I'm doing an ng-repeat of some names, but as the CSV file has characters that people introduce by their own. Sometimes there are spaces or other special characters that end up looking like this in the table:

enter image description here

How can I delete that "question mark symbol" in my table?

my code isn't anything from other world:

Papa.parse("People.csv", {
    download: true,
    header: true,
    skipEmptyLines: 'greedy',
    complete: function(results) {
        $scope.items = results.data;
    }
});

<table>
   <tr>
      <th>Name</th>
   </tr>
   <tr ng-repeat="item in items">
      <td>{{ item.Name }}</td>
   </tr>
</table>

Okay, so I found a method for this, here's the answer:

Papa.parse("People.csv", {
    download: true,
    header: true,
    encoding: 'utf-8', //<---- this did nothing
    skipEmptyLines: 'greedy',
    complete: function(results) {
        $scope.items = results.data;
        var items = $scope.items;

        items.forEach(function(item, index) {

          //I tried to replace the weird character with this but it didn't work on IE (I need it to work in there)
          //item.Name = item.Name.replace(/\uFFFD/g, '');

          //So I did it this way, I tell only the character that I allow to show and to erase any other
          item.Name = item.Name.replace(/[^a-z0-9 ,.?!]/ig, '');
        });
    }
});
Soul Eater
  • 505
  • 1
  • 7
  • 20
  • If you UTF-8 your content from the CSV, those special chars should correctly display. If you want them removed anyway, have a look at https://stackoverflow.com/questions/6555182/remove-all-special-characters-except-space-from-a-string-using-javascript – Sorix Oct 30 '19 at 15:06
  • @Sorix how exactly can I UTF-8 the content of the CSV? I mean, the html has the meta tag `` – Soul Eater Oct 30 '19 at 20:34
  • Have a look at this https://stackoverflow.com/questions/36002183/papaparse-proper-encoding-for-strange-characters – Sorix Oct 31 '19 at 09:41

0 Answers0