This snippet will give you the ChangeEncoding extension method for C# and VB.NET.

Sample C#

public static string ChangeEncoding(this string input, Encoding encoding)
{
	var bytes = encoding.GetBytes(input);
	return encoding.GetString(bytes);
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function ChangeEncoding(input As String, encoding As Encoding) As String
	Dim bytes = encoding.GetBytes(input)
	Return encoding.GetString(bytes)
End Function

One thought on “ChangeEncoding extension method for C# and VB.NET”

Leave a Reply