Mega Code Archive

 
Categories / VB.Net / Data Types
 

Encode the original string using the ASCII encoder

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       Dim bytes() As Byte = enc.GetBytes(str1)       For Each byt In bytes          Console.Write("{0:X2} ", byt)       Next              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       End If    End Sub End Module