How can we read files with double byte characters into a string

G

Guest

This may not be a problem in CF, but I'm working on CF so I just post here.

I have a program needs to read some text file created with double byte
characters, I have try using the streamreader as usual, but it cause problem
no matter which encoding system is used (I can only find: ASCII,
BigEndianUnicode, Unicode, UTF7 and UTF8), those double byte characters has
been converted.

I also try to use binary reader to read the file, it can read all single
bytes correctly, but I have problem to put these characters into a string, as
some of them are single byte characters and some of them are double, it may
need to combine the double byte characters by myself.

According to the MSDN, it seems that there has an option of DBCS for some
character functions (eg., Chr, ChrW), I want to know if there has any option
to read the whole file into a string using DBCS encoding.

Thanks in advance!
 
A

Alex Feinman [MVP]

You should not have trouble reading DBCS (or any MBCS) files provided that:
a) your device supports the necessary codepage
and
b) you have used that codepage to create an instance of Encoding class

For example Encoding class instance for Simplified Chinese can be obtained
by calling Encoding.GetEncoding(54936 ). GetEncoding will throw an exception
if the device OS does not support this encoding.
 
G

Guest

Thanks for you help.

I can solve the problem with GetEncoding("Big5") method now.

Thanks again!
 

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