FileHelpers - How to read in ® character?
Asked Answered
Z

1

8

I am reading in a CSV file and everything is working correctly. All fields are going to the correct places but it is converting ® to �.

var engine = new FileHelperEngine(typeof(T));
return engine.ReadStream(new StreamReader(stream)) as T[];

Any ideas on how to prevent this from happening?

EDIT:

With the help of spender I got this to work:

var engine = new FileHelperEngine(typeof(T), Encoding.UTF8);
return engine.ReadStream(new StreamReader(stream, Encoding.UTF8)) as T[];

I had to set the encoding in BOTH places for this to work. Otherwise I saw weird results.

Zulazulch answered 5/9, 2013 at 14:46 Comment(4)
What encoding are you using?Mcconnell
Read "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" by Joel Spolsky.Amylose
Try using the UTF8 encoding when reading.Finsen
My problem was solved by adding Encoding.UTF8 in new FileHelpserEngine(Encoding.UTF8). I was handling Urdu ( Pakistani Official Lanugae ) (arabic writing). ThankingAmplexicaul
U
7

Set the proper encoding on your StreamReader.

http://msdn.microsoft.com/en-us/library/ms143456.aspx

Underscore answered 5/9, 2013 at 14:47 Comment(3)
I have been changing the Encoding on the FileHelpers Engine, I will try to change it on the stream now.Zulazulch
It's a suspiciously named method called ReadStream that, in fact, doesn't read the stream.Underscore
@Underscore that's hilarious and also incredibly sad and frustrating all at the same time!Selmner

© 2022 - 2024 — McMap. All rights reserved.