473,725 Members | 2,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encoding: how to convert ISO-8559 to Unicode

1 New Member
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 get the db to translate to UTF-8 for non technical reasons.

So I have a string coming back with the character œ (ISO value 156). this character appears in .NET as a box character because 156 is not a valid Unicode character value.

I have been scratching my head over this one and have produced a series of tests to try to get the conversion correct.

My code is below followed by the output:

Expand|Select|Wrap|Line Numbers
  1.             string sybaseRawString = DataAccessLayer.GetXXX();
  2.  
  3.             Encoding iso = Encoding.GetEncoding("iso-8859-1");
  4.             Encoding sbcs = Encoding.Default; //SBCSCodePageEncoding
  5.             Encoding unicode = Encoding.Unicode;
  6.             Encoding utf8 = Encoding.UTF8;
  7.  
  8.             byte[] isoBytes = iso.GetBytes(sybaseRawString);
  9.             byte[] sbcsBytes = sbcs.GetBytes(sybaseRawString);
  10.             byte[] utf8Bytes = Encoding.Convert(iso, utf8, isoBytes);
  11.             byte[] unicodeBytes = Encoding.Convert(utf8, unicode, utf8Bytes);
  12.  
  13.             WriteLine("SYBASE ISO-8559 STRING");
  14.             WriteLine(sybaseRawString);
  15.             WriteLine(ToString(isoBytes));
  16.  
  17.             WriteLine("ISO -> SBCS ENCODED STRING");
  18.             WriteLine(new String(sbcs.GetChars(sbcsBytes)));
  19.             WriteLine(ToString(sbcsBytes));
  20.  
  21.             string expected = "FTSE TECHMARK 100 (œ)"; 
  22.             WriteLine("EXPECTED .NET STRING");
  23.             WriteLine(expected);
  24.             WriteLine(ToString(Encoding.Unicode.GetBytes(expected)));
  25.  
  26.             WriteLine("ISO -> UNICODE");
  27.             WriteLine(new String(unicode.GetChars(unicodeBytes)));
  28.             WriteLine(ToString(unicodeBytes));
  29.  
  30.             WriteLine("ISO -> UTF8");
  31.             WriteLine(new String(utf8.GetChars(utf8Bytes)));
  32.             WriteLine(ToString(utf8Bytes));
  33.  
  34. nb. I have replaced the box chars with question marks apart from SBCS which did produce a question mark. This is because html understands them and translates them to œ!!!
  35.  
  36.  

The output in the DEBUG window is as follows:

SYBASE ISO-8559 STRING
FTSE TECHMARK 100 (?)
46-54-53-45-20-54-45-43-48-4D-41-52-4B-20-31-30-30-20-28-9C-29

ISO -> SBCS ENCODED STRING
FTSE TECHMARK 100 (?)
46-54-53-45-20-54-45-43-48-4D-41-52-4B-20-31-30-30-20-28-3F-29

EXPECTED .NET STRING
FTSE TECHMARK 100 (œ)
46-00-54-00-53-00-45-00-20-00-54-00-45-00-43-00-48-00-4D-00-41-00-52-00-4B-00-20-00-31-00-30-00-30-00-20-00-28-00-53-01-29-00

ISO -> UNICODE
FTSE TECHMARK 100 (?)
46-00-54-00-53-00-45-00-20-00-54-00-45-00-43-00-48-00-4D-00-41-00-52-00-4B-00-20-00-31-00-30-00-30-00-20-00-28-00-9C-00-29-00

ISO -> UTF8
FTSE TECHMARK 100 (?)
46-54-53-45-20-54-45-43-48-4D-41-52-4B-20-31-30-30-20-28-C2-9C-29



However when I view this in NUnit. all the ? appear correctly as œ albeit every so slightly different to the Expected .NET version (ISO vs Unicode??), is NUnit is detecting the encoding format of the char and printing it correctly?

My question is how do I get from my original Sybase ISO-8559 string to the Expected .NET bytes (Unicode) so that I can be sure that all of my .NET apps will display the characters correctly.


Many thanks for any help received!
Dec 13 '07 #1
0 5066

Sign in to post your reply or Sign up for a free account.

Similar topics

10
5540
by: lawrence | last post by:
Validator chokes on my pages now because I started sending an character encoding header of UTF-8 but the page is full of non UTF-8 characters. Anyway quick way to convert them? http://validator.w3.org/check?uri=http%3A%2F%2Fwww.krubner.com%2F
8
607
by: Demon News | last post by:
I'm trying to do a transform (Using XmlTransform class in c#) and in the Transform I'm specifying the the output xsl below: <xsl:output method="xml" encoding="UTF-8" indent="no"/> the resulting xml ends up with the following declaration: <?xml version="1.0" encoding="utf-16"?> changing the encoding to utf-16, is there something I'm doing wrong? Is it
5
28299
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 for Japanese characters encoded as "iso-2022-jp" but does not for "shift-jis" What looked straight forward is proving less so, my test code looks like this: <%@ Page Language="C#"%>
5
13739
by: Robert-Paul | last post by:
I have some big trouble getting special characters right when reading from a mailbox. I have a class that reads e-mails from a mailboxusing pop3 (language C#). I have tried various approaches from suggestions that I have received from newsgroups. Here's a small sample from how the e-mail looks like just after it is received: (some headers removed) MIME-Version: 1.0 Content-Type: text/plain;
4
8843
by: fitsch | last post by:
Hi, I am trying to write a generic RSS/Atom/OPML feed client. The problem is, that those xml feeds may have different encodings: - <?xml version="1.0" encoding="ISO-8859-1" ?>... - <?xml version="1.0" encoding="utf-8" ?>... - ... I am using the WebRequest functionality to get the feeds. So, my code
0
493
by: 6kjfsyg02 | last post by:
I have written a client to a web service. I use ASP.NET 1.1 for the client. It worked until I tried to send accented characters. Then the service answered that my signature is not valid. I was told by the people running the service that their host takes ISO-8859-1 (Latin1) and nothing else. I had been sending the default UTF-8. I tried to send Latin1 with this: RequestEncoding= System.Text.Encoding.GetEncoding( "ISO-8859-1");
3
5675
by: Dale Strickland-Clark | last post by:
A colleague has asked me this and I don't know the answer. Can anyone here help with this? Thanks in advance. Here is his email: I am trying to parse an HTML document using the xml.dom.minidom parser and then outputting a valid HTML document, all using the ISO-8859-1 charset. For example: My input:
4
8375
by: Christina | last post by:
Hey Guys, Currently, I am using the below code: Dim oReqDoc as XmlDocument Dim requiredBytes As Byte() requiredBytes = System.Text.UTF8Encoding.UTF8.GetBytes(oReqDoc.InnerXml). Here, I am encoding my xml string in UTF8 format.
3
1670
by: Neil Cerutti | last post by:
How do I cope with faulty encoding settings? I'm writing an application that needs all internal character data to be stored in iso-8859-1. It also must allow input and output using stdin and stdout. This works just fine with the Windows binary of Python. sys.stdin.encoding is correctly set to the encoding of the current terminal ('cp437').
6
1683
by: ThunderMusic | last post by:
Hi, We are trying to encode to ISO-8859-1, but we have problems doing it using the encoders in .NET. We get some unknown characters in some culture which comes out fine if we post (from IE) from a page in ISO-8859-1 to another page using ISO-8859-1, but cannot take a .NET string or a UTF-8 string, convert it in ISO-8859-1 and display it with this encoding using the same content in the string... Are there anyone that know how IE does it?...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8099
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.