How to use streamreader to reader chinese newsgroup article and display it properly?

K

kaede

Hi all,

I am new to C# and currently writing a Nntp client to read article
from a chinese newsgroup. I am curious how to decode the chinese
character using streamreader and display it properly on Win2K and
WinXP?

I have tried the following:

// send XOVER commands to get the header XOVER 1234-1234

// read the header (subject, from, date, arthur)
Streamreader sr = new Streamreader(nntpStream, Encoding.Default); //
1
string str = sr.ReadLine();
listbox.Item.Add(str);

the output of 3 will shows some wierd characters. I tried changing the
encoding to UTF7/UTF8/Unicode, on both win2k and winXP, it is still
showing wierd characters.

Can anyone show me how to read and decode and display the chinese
character properly? Thanks

Kaede
 
D

Daniel O'Connell [C# MVP]

kaede said:
Hi all,

I am new to C# and currently writing a Nntp client to read article
from a chinese newsgroup. I am curious how to decode the chinese
character using streamreader and display it properly on Win2K and
WinXP?

I have tried the following:

// send XOVER commands to get the header XOVER 1234-1234

// read the header (subject, from, date, arthur)
Streamreader sr = new Streamreader(nntpStream, Encoding.Default); //
1
string str = sr.ReadLine();
listbox.Item.Add(str);

the output of 3 will shows some wierd characters. I tried changing the
encoding to UTF7/UTF8/Unicode, on both win2k and winXP, it is still
showing wierd characters.

Well, for one, you should be examining the charset returned in the
Content-Type header(assuming it is set in the message).

However, the best default would probably be a strictly Chinese encoding. I
believe Big5 is one, you'll have to look up any others.
 
K

kaede

Daniel O'Connell said:
Well, for one, you should be examining the charset returned in the
Content-Type header(assuming it is set in the message).

However, the best default would probably be a strictly Chinese encoding. I
believe Big5 is one, you'll have to look up any others.

Do you know how do I set the encoding to Big5? Should I used
StreamReader using Encoding.Default to examine the Content-Type. Then,
open another streamReader with the appropriate encoding to get the
article?

Do you know of any sample code that show me how to do that?

Thanks very much
Kaede
 
D

Daniel O'Connell [C# MVP]

kaede said:
Do you know how do I set the encoding to Big5? Should I used

Encoding.GetEncoding("Big5"); I think
StreamReader using Encoding.Default to examine the Content-Type. Then,
open another streamReader with the appropriate encoding to get the
article?

That I am not sure about. I think the character set for mime headers is set,
but I really don't know for sure, -_-.

Big5, however, is likely compatible with ASCII in its lower 7 bits, much as
most other encodings are.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top