Re: Convert Encoding from Shift-JIS to UTF-8
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 10/28/04
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Conversion struct/class <--> array"
- Previous message: Nicholas Paldino [.NET/C# MVP]: "Re: form hide"
- In reply to: DbNetLink: "Re: Convert Encoding from Shift-JIS to UTF-8"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 28 Oct 2004 19:26:22 +0100
DbNetLink <robin@____dbnetlink.co.uk> wrote:
> >> If you want the UTF-8 encoded bytes, just use Encoding.UTF8.GetBytes(S)
>
> Is that not what I am doing in the line:
>
> Response.Write( SourceEncoding.GetString( TargetEncoding.GetBytes(
> S ) ) );
No. You're converting the string into UTF-8, but then using the result
as if it were a valid shift-jis-encoded byte array.
> Given the earlier line:
>
> Encoding TargetEncoding = Encoding.UTF8;
>
> I did read the link but was unable to relate it directly to my problem of
> converting one encoding to another using .Net.
It gives the fundamentals, which should explain why the line of code at
the top is a really bad idea.
> If it is simply down to an error in my code perhaps you could point it out
> as I have already spent 2 days on trying to understand what I am doing wrong
> and would love to be put out of my misery :(
You should just be able to use the string, without venturing into
encodings at all.
If that's not working, you need to work through it step by step - see
http://www.pobox.com/~skeet/csharp/debuggingunicode.html
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Conversion struct/class <--> array"
- Previous message: Nicholas Paldino [.NET/C# MVP]: "Re: form hide"
- In reply to: DbNetLink: "Re: Convert Encoding from Shift-JIS to UTF-8"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|