VB.NET System.Text.Encoding Conversion Example
VB.NET System.Text.Encoding Conversion ExampleI ran into an issue on one of the ASP.net applications where the encoding was being passed in as UTF-8 but need to be Window2-1252 or ISO-8859-1 to handle the French encoding.
The Default encoding was ISO
Dim resbytes() As Byte = System.Text.Encoding.UTF8.GetBytes(Response.ToCharArray)
Response = System.Text.Encoding.Default.GetString(System.Text.Encoding.Convert(System.Text.Encoding.Default, System.Text.Encoding.UTF8, resbytes))
Here the Default is in the source and it would convert to UTF8
Dim resbytes() As Byte = System.Text.Encoding.UTF8.GetBytes(Response.ToCharArray)
Response = System.Text.Encoding.Default.GetString(System.Text.Encoding.Convert(System.Text.Encoding.Default, System.Text.Encoding.UTF8, resbytes))
Above the bold highlights the String to Byte convertion and then being passed back to a string.
0 comments :