Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| ' Visual Basic .NET Document | |
| Option Strict On | |
| ' <Snippet2> | |
| Imports System.Text | |
| Module Example | |
| Public Sub Main() | |
| Dim enc As Encoding = Encoding.Ascii | |
| Dim str1 As String = String.Format("{0} {1} {2}", ChrW(&h24C8), ChrW(&h2075), ChrW(&h221E)) | |
| Console.WriteLine(str1) | |
| For Each ch In str1 | |
| Console.Write("{0} ", Convert.ToUInt16(ch).ToString("X4")) | |
| Next | |
| Console.WriteLine() | |
| Console.WriteLine() | |
| ' Encode the original string using the ASCII encoder. | |
| Dim bytes() As Byte = enc.GetBytes(str1) | |
| Console.Write("Encoded bytes: ") | |
| For Each byt In bytes | |
| Console.Write("{0:X2} ", byt) | |
| Next | |
| Console.WriteLine() | |
| Console.WriteLine() | |
| ' Decode the ASCII bytes. | |
| Dim str2 As String = enc.GetString(bytes) | |
| Console.WriteLine("Round-trip: {0}", str1.Equals(str2)) | |
| If Not str1.Equals(str2) Then | |
| Console.WriteLine(str2) | |
| For Each ch In str2 | |
| Console.Write("{0} ", Convert.ToUInt16(ch).ToString("X4")) | |
| Next | |
| Console.WriteLine() | |
| End If | |
| End Sub | |
| End Module | |
| ' The example displays the following output: | |
| ' Ⓢ ⁵ ∞ | |
| ' 24C8 0020 2075 0020 221E | |
| ' | |
| ' Encoded bytes: 3F 20 3F 20 3F | |
| ' | |
| ' Round-trip: False | |
| ' ? ? ? | |
| ' 003F 0020 003F 0020 003F | |
| ' </Snippet2> | |