UTF7 or UTF8

  • Thread starter Thread starter Guoqi Zheng
  • Start date Start date
G

Guoqi Zheng

It is a strange, I can not understand when to use UFT7 and when to use UTF8

Supposed I have the following
Dim b As Byte()
ReDim b(5)
b(0) = 12
b(1) = 23
b(2) = 33
b(3) = 44
b(4) = 251
b(5) = 252

If I use
Dim aa As String = System.Text.Encoding.UTF7.GetString(b)

It will return the correct string. b

But if I use
Dim aa As String = System.Text.Encoding.UTF8.GetString(b)
Byte 251, 252 are missing from the output...

Does something understand why it is this? and when I use UTF7 and when to
use UTF8????
 
Guoqi Zheng said:
It is a strange, I can not understand when to use UFT7 and when to use UTF8

Almost never use UTF-7. It's basically used in mail and nothing else.
Supposed I have the following
Dim b As Byte()
ReDim b(5)
b(0) = 12
b(1) = 23
b(2) = 33
b(3) = 44
b(4) = 251
b(5) = 252

If I use
Dim aa As String = System.Text.Encoding.UTF7.GetString(b)

It will return the correct string. b

What do you view as "the correct string"?
But if I use
Dim aa As String = System.Text.Encoding.UTF8.GetString(b)
Byte 251, 252 are missing from the output...

That's because you haven't given a proper UTF-8 encoded character.
Does something understand why it is this? and when I use UTF7 and
when to use UTF8????

I think you're misunderstanding what the two encodings (and encodings
in general) are doing.

See http://www.pobox.com/~skeet/csharp/unicode.html for the basics.
 
Back
Top