473,569 Members | 2,691 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 7134
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********@NOSP AM.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(pa th,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.WriteLi ne(c);

}
}
}
catch (Exception e)
{
Console.WriteLi ne("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********@NOS PAM.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.co m>
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
5164
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 simply paste the chinese characters from a Word document into my html editor between <P> tags using the PMingLiU or SimSun font but it just enters...
4
6626
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 HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8"> ' create and open the connection to the Excel file Set conn =...
2
2826
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 new text field, in one of my tables. Pasted some chinese text in the field(datasheet view), and the chinese text is sideways. The chinese character...
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 encoded with UTF-7. In order to let SAP display chinese characters correctly, i also need to encode my chinese data by UTF-7. However, i need to...
8
11942
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 part of a datagrid. When an input textbox is displayed it does not display chinese characters, but rather the unicode characters stored in the mssql...
7
4288
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 charactes, I have to use the following code to let it display on the web page: Public Function ToSCUnicode(ByVal str As String) As String Dim enc1252...
3
2843
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 characters they come out as ??. Here's a snippet. Also here is my sample xml file: http://dev4.labwerks.com/research/1_homepage.xml Response.Charset =...
0
1162
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 only read out these 2 strings: " is a Chinese person's name" and "English". Need I make some conversion? Private Sub WriteTextFile Dim file1 As...
2
4019
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 have tried out and all characters are displayed well, if ONLY for me to send it to webmail such as Yahoo!/Gmail. However, I was unable to read the...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.