0

I have a C#.net console application which reads data from a text file and updates it to the database. The file will have Scandinavian characters and other language characters. This is how I read the file in my app

using (StreamReader sr = new StreamReader(openFileDialog1.FileName)) 

but this scrabled the output charcters

I tried using utf8 to read the file but it was returning characters similar to chinese.

using (StreamReader sr = new StreamReader(openFileDialog1.FileName,Encoding.UTF8))

Why is this not working?

Then I tried using the following and its returning the correct characters.

using (StreamReader sr = new StreamReader(openFileDialog1.FileName,Encoding.GetEncoding(1252)))

My question is will the last method help in converting all the characters from different languages or only scandinavain charcters.

I dont have much idea on encoding if someone can explain me how it works. It would be very helpful.

1
  • What is the encoding of your file? I would recommend you using UTF-8 with BOM. If there's no BOM .NET has no way of knowing what how this file is encoded so it will revert to system default. Commented Jul 25, 2010 at 21:37

1 Answer 1

1

Here is The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

About 1252 read here: http://en.wikipedia.org/wiki/ISO_8859-1 . This encoding covers most European languages (with latin script), including but limited to Scandinavian.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.