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:
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, '');
});
}
});