473,503 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how can i read Chinese using C#

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
3 7112
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5154
by: Ian | last post by:
Hi, I've got an english site designed that I need to translate into Chinese. I've got the Chinese wording to work with but I can't figure out how to get it into my code. I thought I could...
4
6620
by: see_mun_lee | last post by:
I use asp to develop a web page to read an excel file containing Chinese Character then display it in the web page. Unfortunately, I cant display it!!! it will display (?????????). <META...
2
2801
by: bob | last post by:
Im having a wierd chinese font issue in Access 2000. I installed the chinese support for access 2000, have all the windows stuff setup, even have 10-12 other chinese fonts installed. I made a...
0
724
by: Alex Chan | last post by:
Hi group, I am writing a RFC Server with SAP.NET Connector to connect to SAP. There are chinese characters passing back and forth. I found that all chinese characters sending from SAP are...
8
11930
by: pabv | last post by:
Hello all, I am having a few issues with encoding to chinese characters and perhaps someone might be able to assist. At the moment I am only able to see chinese characters when displayed as...
7
4280
by: c.verma | last post by:
I have a web application. There is a page which has a datagrid on it.The datagrid displays the data that comes from SAP. SAP sends the chinese characters to this grid. Before I display CHinese...
3
2833
by: msnews.microsoft.com | last post by:
Hey there, I'm having trouble reading Simple Chinese characters from an XML document in an ASP file, I want to update the database based on what is in the file. Everytime, I read in the...
0
1156
by: Peter | last post by:
Hi,everybody, If I create a text file like "Sub WriteTextFile" I can read the file "file1.txt" using "Sub ReadTextFile" correctly, Whereas If I create the same text file using NotePad.exe I can...
2
4005
borisding
by: borisding | last post by:
Hi there, I'm using Jmail for sending email with some attachments. Basically, I will need to send out email with the contents in unicode characters such as Simplified Chinese, Japanese etc. I...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.