[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Streamreader Codepage Problems

Posted on 2008-02-08
2
Medium Priority
?
1,809 Views
Last Modified: 2013-11-26
I'm having some problems with a text file i have received from a customer, that I need to load into a dataset with a Streamreader.

I have tried to use the Encoding object, but the streamreader still doesn't read special characters correctly.

If i open the textfile in Notepad and save it as Unicode, it does not seem to matter which Encoding i tell the streamreader to use, it comes in correctly regardless.

If i do not change the file in notepad, the same scenario applies, it does not seem to matter which encoding i use, it still comes in WRONG !  :(

Please excuse my ignorance, this is my first try with codepages and encoding, and im under deadline pressure. Sorry for lack of any important info, please ask me what need to be asked.

Thanks 1.000.000 in advance !

Cheers
0
Comment
Question by:jeschrper
2 Comments
 
LVL 9

Accepted Solution

by:
sognoct earned 1500 total points
ID: 20849535
ASCII is a 7-bit encoding and has not all characters.  You must discover what kind of  encoding has your file and tell the StreamReader. By default it uses UTF8Encoding.

Try
StreamReader sr = new StreamReader("foo.txt",System.Text.Encoding.Default);

That will us your computer's regional settings to get the current code page, or figure out what code page is used for your file and specify it.
0
 

Author Closing Comment

by:jeschrper
ID: 31429159
Thank you for input. I am an idiot, problem caused by bad code :(
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question