Mega Code Archive

 
Categories / VB.Net / Internationalization
 

Get an encoding for code page 1252 (Western Europe character set)

Imports System.Text Module Example    Public Sub Main()       Dim cp1252 As Encoding = Encoding.GetEncoding(1252)       Dim str As String = String.Format("{0}", ChrW(&h24c8))       For Each ch In str          Console.Write("{0} ", Convert.ToUInt16(ch).ToString("X4"))       Next       Dim bytes() As Byte = cp1252.GetBytes(str)       For Each byt In bytes          Console.Write("{0:X2} ", byt)       Next       Dim str2 As String = cp1252.GetString(bytes)       Console.WriteLine("String round-tripped: {0}", str.Equals(str2))       If Not str.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