Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read Text File With High Bit Characters ( é )

Status
Not open for further replies.

bustell

Programmer
Mar 22, 2002
159
US
How do I open a text file containing high bit characters such as é which is ASCII 233 (E9 hex)?

I've tried different things with stream reader but have not been able to get it to read the line correctly. It reads the line and replaces that character with a ? (63 or 3F).

Here are some things I've tried:
Code:
Using SR As New StreamReader(IO.File.Open(Common.Folder_MM2010MailPieceProcessing & NewFilename, FileMode.Open), True)

Using SR As StreamReader = IO.File.OpenText(Common.Folder_MM2010MailPieceProcessing & NewFilename)

Using SR As New StreamReader(IO.File.Open(Common.Folder_MM2010MailPieceProcessing & NewFilename, FileMode.Open), text.Encoding.ASCII)

Using SR As New StreamReader(IO.File.Open(Common.Folder_MM2010MailPieceProcessing & NewFilename, FileMode.Open), Text.Encoding.UTF8)

After it is open I do SR.ReadLine to get the next line in a string variable.

None of these seem to work. Is there a different way I should open the file? Or a different stream reader?

Thanks in advance for any help!


Pat B
 
Well, looks like this works:

Code:
Using SR As New StreamReader(Common.Folder_MM2010MailPieceProcessing & NewFilename, Text.Encoding.Default)

Don't know that I like using the default as that could change from system to system, but for now it seems to be OK.

If anyone has any thoughts they'll be very much appreciated.

Thank you,


Pat B
 
You need to know the encoding that the file was created with.

ISO-8859-1 (thru ISO-8859-15)
UTF-7, UTF-8
IBM861
etc. etc.

Once you know that, you can use the Encoding class from System.Text to convert it to the Unicode strings that .net uses internally.

There is essentially no way to look at the file and guess -- the originator of the file has to tell you what they used.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top