How to convert string charset?

  • Thread starter Miros³aw Iwanowski
  • Start date
M

Miros³aw Iwanowski

Hello!

I need to conver string (sql statement) from one Polish charset standard
(ISO-8859-2) to another (Win-1250). Using help I managed to create line like
this one:
sql=Encoding.ASCII.GetString(Encoding.Convert(Encoding.GetEncoding("ISO-8859
-2"),Encoding.GetEncoding("windows-1250"),Encoding.ASCII.GetBytes(sql)));
But it doesn't work. I know that ASCII isn't right here because it's 7 bit
representation and special characters are in the "second part" of the
charset.

How should I do it?

Regards
Leon
 
J

Jon Skeet [C# MVP]

Miros³aw Iwanowski said:
I need to conver string (sql statement) from one Polish charset standard
(ISO-8859-2) to another (Win-1250). Using help I managed to create line like
this one:
sql=Encoding.ASCII.GetString(Encoding.Convert(Encoding.GetEncoding("ISO-8859
-2"),Encoding.GetEncoding("windows-1250"),Encoding.ASCII.GetBytes(sql)));
But it doesn't work. I know that ASCII isn't right here because it's 7 bit
representation and special characters are in the "second part" of the
charset.

How should I do it?

Strings themselves are always in unicode, whatever their origin. Unless
you're really dealing with the byte arrays, you shouldn't need to do
any conversion. It sounds like you may have received bad data to start
with, if you're having problems.

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.
 

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