I created a CSV parser that parses CSV's from static resources.
I am returned with a Blob is not a Valid UTF-8 String
error when parsing the character: "–" different from "-". The "–" is apparently still a unicode character:
https://unicodelookup.com/#%E2%80%93/1.
The sheet is being saved as UTF-8 CSV and the data was exporting from Salesforce using data loader 38.0.
Can someone explain why this character is returning the Blob is not a Valid UTF-8 String
even though the character appears to be a UTF-8 character?
CSV:
HEX with bad character:
00:00:00:XXX USER_DEBUG [XX]|DEBUG|4f626a6563742c437573746f6d5f446563696d616c5f5f632c437573746f6d5f5f632c42726f6b656e5f4669656c645f5f630d0a4d794f746865724f626a6563745f5f632c312c412c5858209620546869732068797068656e206973206275737465640d0a
HEX without bad character:
00:00:00:XXX USER_DEBUG [XX]|DEBUG|4f626a6563742c437573746f6d5f446563696d616c5f5f632c437573746f6d5f5f632c42726f6b656e5f4669656c645f5f630d0a4d794f746865724f626a6563745f5f632c312c412c58582020546869732068797068656e206973206275737465640d0a
||||||Update:
Upon opening the file in Notepad, it appears the file was encoded in ANSI, even though excel states the file is encoding in UTF-8 when I open it. After saving at UTF-8 in Notepad, that resolved the symbol issue.
This did not work:
This did:
With this being said are there any capabilities within the blob class or another class to convert the file from ANSI to UTF-8 within Salesforce as opposed to relying on customers to ensure the file is in the correct encoding?
System.debug(EncodingUtil.convertTohex(resource.body));