| |
7.31.3.Convert string to and back: UTF8, UTF7, Unicode and UTF32 |
|
Public Class Tester
Public Shared Sub Main
Dim quote As String = "qqqqqq"
Dim result As New System.Text.StringBuilder
Dim bytesUTF7 As Byte() = System.Text.Encoding.UTF7.GetBytes(quote)
Dim bytesUTF8 As Byte() = System.Text.Encoding.UTF8.GetBytes(quote)
Dim bytesUnicode As Byte() = System.Text.Encoding.Unicode.GetBytes(quote)
Dim bytesUTF32 As Byte() = System.Text.Encoding.UTF32.GetBytes(quote)
result.Append("bytesUTF7.Length = ")
result.AppendLine(bytesUTF7.Length.ToString())
result.Append("bytesUTF8.Length = ")
result.AppendLine(bytesUTF8.Length.ToString())
result.Append("bytesUnicode.Length = ")
result.AppendLine(bytesUnicode.Length.ToString())
result.Append("bytesUTF32.Length = ")
result.AppendLine(bytesUTF32.Length.ToString())
Dim fromUTF7 As String = System.Text.Encoding.UTF7.GetString(bytesUTF7)
Dim fromUTF8 As String = System.Text.Encoding.UTF8.GetString(bytesUTF8)
Dim fromUnicode As String = System.Text.Encoding.Unicode.GetString(bytesUnicode)
Dim fromUTF32 As String = System.Text.Encoding.UTF32.GetString(bytesUTF32)
If (fromUTF7 <> quote) Then _
Throw New Exception("UTF7 Conversion Error")
If (fromUTF8 <> quote) Then _
Throw New Exception("UTF8 Conversion Error")
If (fromUnicode <> quote) Then _
Throw New Exception("Unicode Conversion Error")
If (fromUTF32 <> quote) Then _
Throw New Exception("UTF32 Conversion Error")
Console.WriteLine(result.ToString())
End Sub
End Class
|
|
bytesUTF7.Length = 6
bytesUTF8.Length = 6
bytesUnicode.Length = 12
bytesUTF32.Length = 24 |
|