views:

231

answers:

1

Is there any easy way of converting a windows-1252 string into a Unicode one?

+5  A: 

All strings in .NET are Unicode in memory. If you have a byte array that was generated from a string encoded in 1252, you can recover the string using

Dim S as String = System.Text.Encoding.GetEncoding(1252).GetString(array)

It is now a unicode string in memory. If you then want to encode that string into a UTF-8 byte array for transmission or storage, you would do the converse:

Dim A as byte() = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(S)

(I think that is the right VB syntax!)

Cheeso