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

x
  • 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.

Thanks!

Also, assume I have a working csv parser.  SpecialCharacter.csv
0
freezegravity
Asked:
freezegravity
  • 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

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

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