[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

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.


Also, assume I have a working csv parser.  SpecialCharacter.csv
  • 3
1 Solution
Carlos VillegasFull 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

Carlos VillegasFull Stack .NET DeveloperCommented:
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.
Carlos VillegasFull Stack .NET DeveloperCommented:
Glad to help!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now