VB.NET System.Text.Encoding Conversion Example

VB.NET System.Text.Encoding Conversion Example

I 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.

Share this:

ABOUT THE AUTHOR

Hello We are OddThemes, Our name came from the fact that we are UNIQUE. We specialize in designing premium looking fully customizable highly responsive blogger templates. We at OddThemes do carry a philosophy that: Nothing Is Impossible

0 comments

Powered by Blogger.