By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

how can i read Chinese using C#

P: n/a
Hi!
I am implementing a system that can read Chinese characters from a text file
and do some string manipulations. Can anyone suggest a method on how I can
do file I/O with Chinese?
Thanks.
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The same as usual - except you have to be careful which character
encoding you are using. Take a look at the available constructors for
FileStream etc - you can specify the encoding there (you'll probably
want to use Unicode)

In article <O1**************@TK2MSFTNGP11.phx.gbl>,
ch********@NOSPAM.cuhk.edu.hk says...
Hi!
I am implementing a system that can read Chinese characters from a text file
and do some string manipulations. Can anyone suggest a method on how I can
do file I/O with Chinese?
Thanks.


--
~ James Crowley
http://www.developerfusion.com/
Nov 15 '05 #2

P: n/a
I have tried to change the encoding, but then the results seems strange:

Code:
try
{

using (StreamReader sr = new
StreamReader(path,System.Text.Encoding.UTF8))
{

//This is an arbitrary size for this example.
string c = null;

while (sr.Peek() >= 0)
{
c = null;
c = sr.ReadLine();
Console.WriteLine(c);

}
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}


Result:
SPOT !UA!U!nXqA!nXq!?{!?!i{!Es!_A!?!H!i{!H!
HERE !?!?!??a!??a!??a!a!??a!??a!
Nov 15 '05 #3

P: n/a
Cheryl <ch********@NOSPAM.cuhk.edu.hk> wrote:
I have tried to change the encoding, but then the results seems strange:


Sure, if you try using UTF-8 and it's not actually in UTF-8, it will
look odd. You need to *know* the appropriate encoding - the encoding
the file was saved in to start with. What created the file in the first
place?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.