Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading and Writing Text files containing Japanese characters

Status
Not open for further replies.

aditid

Programmer
May 26, 2003
8
IN
Hello,

I am writing a small tool to automate a process of conversion. The tool reads a text file for some commands and writes the equivalent new command gain to a text file.
I am using streamReader to read and streamwriter to write the text files.The input file contains some comments etc. in japanese which are to be written as it is to the output file.

I am having problem in reading/writing these japanese char. It shows just junk.

Could somebody tell, how to read the double byte japanese characters and write them to the o/p file.

Thanks in anticipation,
Regards,
aditid
 
What encoding is the file in?

In order to use Japanese characters, traditionally you've had to use DBCS (double-byte character set), which dates from the early DOS days. Since Unicode came out, you would use UTF-16 (Unicode) or UTF-8 encoding. But it all depends on what encoding was used to write the file.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hello Chip H,

Thanks for your reply. I think the file was created in Shift JIS encoding. Can u suggest the solution now ?

Regards,
aditid
 
You can do this (from MSDN):
Code:
Encoding enc = Encoding.GetEncoding("shift-jis");
Once you have an encoding object, you use it's Convert method to change a string containing your Shift-JIS data into Unicode, which the rest of .NET can handle.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hello Chip H,

Thanks a lot for your suggestion. I found similar solution on a japanese site. Since I am using streamReader and StreamWriter and the tip on this site was for stream, I used that piece of code. I am giving that code below. Still, thanx fot sparing time and suggesting solution to my problem.
Here are the code lines :

Code:
objReader = New StreamReader(txtPath.Text + "\" + file.Name, System.Text.Encoding.GetEncoding("shift-jis"))

objWriter = New StreamWriter(strdest + "\" + file.Name, False, System.Text.Encoding.GetEncoding("shift-jis"))

Regards,
aditid

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top