String encoding error when reading file

Hello Experts,

When I upload the attached file and compare the "LastName" to an existing value in the database, I get that the strings are not equal. When I debug in visual studio, I get a question mark inside a diamond shape. I understand I probably need to encode the csv file string, but I am not sure how to go about this.

Thanks!

Also, assume I have a working csv parser.  SpecialCharacter.csv
freezegravityAsked:
Who is Participating?
 
Carlos VillegasConnect With a Mentor Full Stack .NET DeveloperCommented:
Hello, your file is in ANSI encoding, try this:
using (System.IO.StreamReader sr = new System.IO.StreamReader(@"C:\SpecialCharacter.csv", System.Text.Encoding.GetEncoding(1252)))
{
    string s = sr.ReadToEnd();
}

Open in new window

0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
0
 
freezegravityAuthor Commented:
Thanks a lot. Turns out I wasn't sending the Encoding parameter into my streamreader and as soon as I did that, things started to work. Also, the link in your second comment helped me understand this thing slightly better.
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Glad to help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.