0

I'm parsing a CSV text file containing some data (with labels, numbers, symbols, ...) using XLSX. At some point, my data are parsed and one of the cell content is '\x80', which is the unicode code of the euro symbol.

const s = "\x80"
console.log({ s }) // => {s: '\x80'}
console.log(s) // => €

When I try to save this variable into my database (Mongodb), it is not recognized as €.

s.replace("\x80", "€") is not a solution for me because some other special characters can showed up while importing files.

How can I convert "\x80" to "€" ?

I try some solutions like unescape( encodeURIComponent( s ) ); but none of them worked.

Edit

XLSX is a library to work with Excel files https://github.com/SheetJS/sheetjs.

Original encoding of the file is windows-1252

Edit 2

It look like it's a browser problem \x80 is working on Chrome but not on Safari nor Firfox.

console.log(s) // Print empty string on Safari => ""

Edit 3

I have created this codebox to reproduce

Here is the difference between chrome and safari codebox demo screenshot

Bogy
  • 944
  • 14
  • 30
  • What is XLSX and how are you using that to parse CSV files? – Bergi Sep 28 '21 at 17:06
  • The string contains the euro symbol just fine. The backslash-escaping only shows up when printing not the string itself, but a string literal (like `console.log` does for the object property). – Bergi Sep 28 '21 at 17:09
  • Is the original encoding Windows-1252? You can use https://github.com/mathiasbynens/windows-1252. – Ry- Sep 28 '21 at 17:13
  • "*XLSX is a library to work with Excel files*" - why would you use that to parse CSV? Use a CSV parser library. – Bergi Sep 28 '21 at 17:44
  • My importation module should work with xls file as well – Bogy Sep 28 '21 at 17:47
  • Please post the content of the CSV file you're trying to parse, the code that does the parsing, and how the output you get is unexpected. – Bergi Sep 28 '21 at 17:51

0 Answers0