PC Review


Reply
Thread Tools Rate Thread

Displaying Extended Latin-1 characters in a multi-lineTextbox

 
 
Paul Bradshaw
Guest
Posts: n/a
 
      19th Dec 2006
I have a weird situation...

I have a unicode text file that contains Latin-1 characters. This code displays fine in unicode text editors, and when converted to ANSI by a tool like EditPad, it looks correct as well. But when I use the code below to load it into a Text box, all the extended characters are stripped ... either the accents are missing, or the character is just plain gone.

using (StreamReader text = File.OpenText(logFilePath))
{
string log = text.ReadToEnd();
LogFileDisplay.Text = log;
}

I'm not sure what I'm missing here. Somewhere, something is transcoding the unicode text... and I want it to just leave it alone, and display it as-is. Any pointers?



EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      19th Dec 2006
<Paul Bradshaw> wrote:
> I have a weird situation...
>
> I have a unicode text file that contains Latin-1 characters. This
> code displays fine in unicode text editors, and when converted to
> ANSI by a tool like EditPad, it looks correct as well. But when I use
> the code below to load it into a Text box, all the extended
> characters are stripped ... either the accents are missing, or the
> character is just plain gone.
>
> using (StreamReader text = File.OpenText(logFilePath))
> {
> string log = text.ReadToEnd();
> LogFileDisplay.Text = log;
> }
>
> I'm not sure what I'm missing here. Somewhere, something is
> transcoding the unicode text... and I want it to just leave it alone,
> and display it as-is. Any pointers?


Files are binary. Strings are text. When you convert between them, you
will *always* end up using an encoding somewhere, even if you think
it's just a "null" encoding.

In the case of StreamReader, the default encoding is UTF-8. If you want
to use a different encoding, you need to specify that. It's a shame
that File.OpenText neither documents what encoding it will use, nor
allows you to specify it.

Use one of the StreamReader constructors instead, either passing in the
filename or opening a stream and then passing that it - along with the
appropriate encoding.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset with non Latin characters? =?Utf-8?B?TGFuZyBEdQ==?= Microsoft Access 0 29th Sep 2006 01:31 PM
Recordset with non Latin characters? =?Utf-8?B?TGFuZyBEdQ==?= Microsoft Access Queries 0 29th Sep 2006 11:34 AM
Where are non-latin characters coming from? =?Utf-8?B?SmFuIEs=?= Microsoft Outlook Discussion 0 29th Jun 2006 11:22 AM
Re: Latin characters and c# / .NET Bruno Jouhier [MVP] Microsoft C# .NET 1 27th Aug 2003 08:53 AM
Re: Latin characters and c# / .NET Jon Skeet Microsoft C# .NET 0 26th Aug 2003 06:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:23 AM.