.NET: Encoding.Convert(...Encoding.Unicode...)

M

Ma³y Piotruœ

Hello,
Could you help me please with encoding transformations in .NET? I am
beginner.
I have some code that nearly works - but I have problem with
converting from fileEncoding to Unicode (Strings are in Unicode).

Dim fe As Encoding 'fileEncoding
Dim ue As Encoding = Encoding.Unicode
Dim fb(0) As Byte 'bytes read
Dim ub As Byte() 'output bytes
....
fe = Encoding.GetEncoding(...) 'fe pobierane z Web.configa
....
fb(0) = br.ReadByte() 'here fb(0) > 0
ub = Encoding.Convert(fe, ue, fb) 'ERROR here: ub is null

Could you explain me please why ub does not contain Unicode bytes? How
to correct the code?
Thank you very much.
(MP)
 
J

Jon Skeet [C# MVP]

Ma³y Piotru? said:
Could you help me please with encoding transformations in .NET? I am
beginner.
I have some code that nearly works - but I have problem with
converting from fileEncoding to Unicode (Strings are in Unicode).

Dim fe As Encoding 'fileEncoding
Dim ue As Encoding = Encoding.Unicode
Dim fb(0) As Byte 'bytes read
Dim ub As Byte() 'output bytes
...
fe = Encoding.GetEncoding(...) 'fe pobierane z Web.configa
...
fb(0) = br.ReadByte() 'here fb(0) > 0
ub = Encoding.Convert(fe, ue, fb) 'ERROR here: ub is null

Could you explain me please why ub does not contain Unicode bytes? How
to correct the code?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 

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