Question Code to convert UTF-8 into Windows-1252?

littlebigman

Well-known member
Joined
Jan 5, 2010
Messages
75
Programming Experience
Beginner
Hello

I googled for this and tried a few things, but I'm still stuck at something so simple.

I simply need to let the user copy some UTF-8 text into the clipboard, convert it to Windows-1252, and paste the output back into the clipboard.

It looks like I need to use the System.Text.Encoding object, but I'm confused about how to use it (strings, byte arrays, etc.)

Would someone have some working code handy by any chance?

Thank you.
 
Last edited:
In case someone else needs the code, here it is (as used in the SharpDevelop IDE instead of MS Visual Studio):
VB.NET:
Public Sub New()
	' The Me.InitializeComponent call is required for Windows Forms designer support.
	Me.InitializeComponent()
	
	Dim w1252 As Encoding = Encoding.GetEncoding(1252)
	
	Dim Str As String
	
	Str = w1252.GetString(Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding(1252), Encoding.Default.GetBytes(Clipboard.GetText)))

	MessageBox.Show(Str)
	
End Sub
 
Back
Top