473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

BIG encoding and UTF8?

We have an application that uses UTF8 everywhere to load / save / process
documents.
One of our clients is having a problem with BIG Encoded files being trashed
after running through our app.

Indeed I have verified that if I go to a website in Taiwan and save the file
in BIG5 and then just load / save the file with a UTF8 text reader / write
some bytes are modified.

How can I correct this? It was my understanding the UTF8 was supposed to be
high byte friendly.

Jul 8 '06 #1
7 4422
You're correct about the UTF8 is multibyte encoding, but big5 is just a
different coding scheme.

When you open the big5 file in a UTF8 editor(I assume you mean the editor
use UTF8 to handle internal strings like .NET applications), some conversion
happens there to ensure it displays correctly. So basically it's no longer
big5 once you get the file loaded.

To "fix" this, it'll depend on what your "editor" is. In VS.NET you can
change the
encoding scheme when you select "Advanced Save Option..." from the "File"
menu.
UltraEdit have a dropdown menu on the "Save" dialog. I suppose you'll find
some
exposed methods if you're automating it with COM+ application.

If the "editor" is written by yourself and it's written with .NET, you
should use Encoding class to do conversion first (Codepage for Big5 is
CP950). I prefer to do a GetBytes() first then write them into a
BinaryWriter.

"EmeraldShield" <em***********@noemail.noemail¼¶¼g©ó¶l¥ó·s»D:et*** ***********@TK2MSFTNGP04.phx.gbl...
We have an application that uses UTF8 everywhere to load / save / process
documents.
One of our clients is having a problem with BIG Encoded files being
trashed after running through our app.

Indeed I have verified that if I go to a website in Taiwan and save the
file in BIG5 and then just load / save the file with a UTF8 text reader /
write some bytes are modified.

How can I correct this? It was my understanding the UTF8 was supposed to
be high byte friendly.

Jul 8 '06 #2
Hi,

Thank you for your post.

Based on my understanding, your question is how to process BIG5 file in
.NET. If I've misunderstood anything, please feel free to post here.

In .NET, a string is a sequential collection of Unicode characters that is
used to represent text. Each Unicode character in a string is defined by a
Unicode scalar value, also called a Unicode code point or the ordinal
(numeric) value of the Unicode character. Each code point is encoded using
UTF-16 encoding.

Encoding is the process of transforming a set of Unicode characters into a
sequence of bytes. Decoding is the reverse. The Unicode Standard assigns a
code point (a number) to each character in every supported script. A
Unicode Transformation Format (UTF) is a way to encode that code point. The
Unicode Standard version 3.2 uses the following UTFs:

* UTF-8, which represents each code point as a sequence of one to four
bytes.
* UTF-16, which represents each code point as a sequence of one to two
16-bit integers.
* UTF-32, which represents each code point as a 32-bit integer.

For a list of .NET supported encodings, please refer to following MSDN
Library article:

#Encoding Class (System.Text)
http://msdn2.microsoft.com/en-us/lib....encoding.aspx

System.IO.StreamReader is designed for character input in a particulear
encoding. StreamReader defaults to UTF-8 encoding unless specified
otherwise, instead of defaulting to the ANSI code page for the current
system.

To open a BIG5 encoding file, you must pass the specified encoding to
StreamReader, for example:

StreamReader sr = new StreamReader(@"c:\temp\1.txt",
Encoding.GetEncoding("big5"));

StreamWriter is like StreamReader, when not specified, will use an instance
of UTF8Encoding to encode the text.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 10 '06 #3
Hi,

I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.

Have a great day!

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 12 '06 #4

Hello,

Sorry I got real sick last week and just got back to the office. I have not
yet tried any of your suggestions, but I will and post my findings.

My big problem right now is that if I use a UTF-8 encoded stream and just
load / save (using Dot Net - not some editor) the bytes are different.

I have tried to use different settings, but I cannot get Dot Net to process
a BIG5 file without corruption unless I specifiy BIG5 as the encoding type.
This does not work as I don't know if it is BIG5 or not until after it is
loaded...

These are emails we process, but for my test I used IE to go to a Taiwanese
site and save the page as BIG5 encoding.

Jason

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:H$**************@TK2MSFTNGXA01.phx.gbl...
Hi,

I am interested in this issue. Would you mind letting me know the result
of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.

Have a great day!

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jul 18 '06 #5
Hi Jason,

Thank you for your update.

Unfortunately StreamReader can only detect the encoding by looking at the
first three bytes of the stream. It can only recognizes UTF-8,
little-endian Unicode, and big-endian Unicode text if the file starts with
appropriate byte order marker (BOM). Otherwise, the user must provide the
correct encoding. Also note this Caution in the documentation of
StreamReader:

When you compile a set of characters with a particular cultural setting and
retrieve those same characters with a different cultural setting, the
characters might not be interpretable, and could cause an exception to be
thrown.

For more information, please refer to MSDN Library:

#StreamReader Constructor (Stream, Encoding)
http://msdn2.microsoft.com/en-us/library/ms143456.aspx

Normally a HTML file will have meta data in it to specify which encoding
it's using, thus the browser will display it correctly. For example, an
UTF-8 encoded html file will have:

<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">

Since you mentioned your program is processing email, depending on the
email format, it may have some meta data in its header which describes its
encoding.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 18 '06 #6
Unfortunately StreamReader can only detect the encoding by looking at the
first three bytes of the stream. It can only recognizes UTF-8,
little-endian Unicode, and big-endian Unicode text if the file starts with
appropriate byte order marker (BOM). Otherwise, the user must provide the
correct encoding. Also note this Caution in the documentation of
StreamReader:
I thought that UTF-8 with high order detection disabled would preserve the
original data. Is this not the case? How would we preserve the data? In
c++ you could always just read WORDs and write them without fear of
corruption.

All email is supposed to be UTF8 friendly (You cannot send high order
commands), but it is not the first 3 bytes. These are actual SMTP
communications. Some of the attachments or email are trashed. The email
itself does not have an identifier to tell us it is BIG5 (I will double
check that today when I get in the office).
Since you mentioned your program is processing email, depending on the
email format, it may have some meta data in its header which describes its
encoding.
We are the email processor, so anything added in the header will have to be
done in our app. That is the problem. We have attachments in Outlook from
Chinese customers using BIG5 that are being trashed and we cannot figure out
why if we use UTF8 everywhere.

Thanks,

Jason
Jul 18 '06 #7
EmeraldShield wrote:
Unfortunately StreamReader can only detect the encoding by looking at the
first three bytes of the stream. It can only recognizes UTF-8,
little-endian Unicode, and big-endian Unicode text if the file starts with
appropriate byte order marker (BOM). Otherwise, the user must provide the
correct encoding. Also note this Caution in the documentation of
StreamReader:

I thought that UTF-8 with high order detection disabled would preserve the
original data. Is this not the case? How would we preserve the data? In
c++ you could always just read WORDs and write them without fear of
corruption.
If you need to preserve text data without knowing the encoding, you
need to treat it as opaque binary data - just read it as bytes.
All email is supposed to be UTF8 friendly (You cannot send high order
commands), but it is not the first 3 bytes. These are actual SMTP
communications. Some of the attachments or email are trashed. The email
itself does not have an identifier to tell us it is BIG5 (I will double
check that today when I get in the office).
It should have. There should be a header somewhere saying what encoding
to use - otherwise there are numerous possible ones.
Since you mentioned your program is processing email, depending on the
email format, it may have some meta data in its header which describes its
encoding.

We are the email processor, so anything added in the header will have to be
done in our app. That is the problem. We have attachments in Outlook from
Chinese customers using BIG5 that are being trashed and we cannot figure out
why if we use UTF8 everywhere.
I think you're still trying to treat UTF-8 as a silver bullet, and it's
not. You can't treat arbitrary binary data (which is what the
BIG5-encoded text effectively is, as far as you're concerned) as a
valid UTF-8-encoded string and expect to write it out without losing
data.

If you don't want to lose any data and you don't know what the encoding
is, just read and write is as bytes instead of text.

Jon

Jul 18 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm...
5
by: DbNetLink | last post by:
I am trying to convert some Japanese text encoded as Shift-JIS/ISO-2022-JP to UTF-8 so I can store all data in my database with a common encoding. My problem is the encoding conversion code works...
7
by: Jim Lawton | last post by:
Hello, tried this in framework.aspnet without any luck so far, maybe someone here has a comment ... TIA, Jim ..net c# httphandler straight html form at browser. GBP pound sign problem (I...
2
by: Jim Lawton | last post by:
Hi, ..net c# httphandler straight html form at browser. GBP pound sign problem (I know I know - I *can* decode it, but I've got to understand what and why I should be doing stuff) I am...
11
by: Dale | last post by:
I am trying to create a System.Text.Encoding for ISO-8859-1 in a similar fashion to this line that creates an Encoding for UTF8: private Encoding encoding = Encoding.UTF8; Then, I want to test...
0
by: kellner | last post by:
Hello, I'm parsing a chunk of XML code and would like to add attribute values to individual tags if these are lacking. This is with perl 5.8.6, libxml2 2.6.17, XML::LibXML 1.58. Basically, I...
0
by: Tim Arnold | last post by:
Hi, I'm beginning to understand the encode/decode string methods, but I'd like confirmation that I'm still thinking in the right direction: I have a file of latin1 encoded text. Let's say I put...
0
by: deloford | last post by:
Hi This is going to be a question for anyone who is an expert in C# Text Encoding. My situation is this: I have a Sybase database which is firing back ISO-8559 encoded strings. I am unable to...
0
by: damonwischik | last post by:
I use emacs 22 and python-mode. Emacs can display utf8 characters (e.g. when I open a utf8-encoded file with Chinese, those characters show up fine), and I'd like to see utf8-encoded output from my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.