Hi,
I am reading value from csv using "csvReader.GetField
but m getting � instead of special symbols.
ex.
Original value -
Beautiful Class “A” office space in Greenfield Corporate Center. Many private offices, conference rooms, windows, beautiful setting with easy access to highways and employee base. All operating cost for base year included in rent, except janitorial.
Csv output -
Beautiful Class �A� office space in Greenfield Corporate Center. Many private offices, conference rooms, windows, beautiful setting with easy access to highways and employee base. All operating cost for base year included in rent, except janitorial.
Can you please look into dis.
Many Thanks.
Can you provide the csv line you're seeing this on? Also, are you using any special type of encoding on the file?
You need to set the encoding on the TextReader you pass into CsvHelper. CsvHelper just gets characters from the reader and doesn't do deal with encodings.
Thanx Josh and Phillijw,
encoding TextReader works for me.
@vikramlokhande will you please provide an example of your fix. I'm also struggling with this.
new StreamReader(stream, Encoding.UTF8)
You need to specify the correct encoding.
@JoshClose I am facing this issue while reading a Csv.
Configuration I have:
var csvConfig = new CsvConfiguration
{
Encoding = Encoding.UTF8,
HasHeaderRecord = true,
IgnoreHeaderWhiteSpace = true,
IsHeaderCaseSensitive = false,
IgnoreBlankLines = true,
CultureInfo = new CultureInfo("es")
};
And the Output is
Cargando anomal�as...
No se encontraron anomal�as
Descripci�n
Abrir panel del cl�ster
For
Cargando anomalías...
No se encontraron anomalías
Descripción
Abrir panel del clúster
It will work for me if I use Encoding.GetEncoding("ISO-8859-1"), but the characters are supported in UTF-8 too.
It will work for me if I use Encoding.GetEncoding("ISO-8859-1"), but the characters are supported in UTF-8 too.
This worked for me. Using the Encoding.UTF8 did not work for me.
@grahampaull take a look at the linked issue. If Encoding.GetEncoding("ISO-8859-1") worked for you, it means the file was encoded that way and not as UTF-8. The two encodings are not completely interchangeable. After the first 128 characters UTF-8 uses 2 bytes and ISO-8859-1 still uses 1 byte to store the character.
Most helpful comment
You need to set the encoding on the
TextReaderyou pass into CsvHelper. CsvHelper just gets characters from the reader and doesn't do deal with encodings.