Encoding UTF8 string to ISO-8859-1 String (VB.NET)

后端 未结 5 1825
星月不相逢
星月不相逢 2020-12-11 22:11

I need to convert UTF8 string to ISO-8859-1 string using VB.NET.

Any example?


emphasized textI have tried Latin function and not runs. I recei

5条回答
  •  有刺的猬
    2020-12-11 23:02

    The encoding ISO-8859-1 is more commonly called Latin-1. You can get this encoding by doing the following

    Dim latin1 = Text.Encoding.GetEncoding(&H6FAF)
    

    The full conversion can be done by the following

    Public Function ConvertUtf8ToLatin1(Dim bytes As Byte()) As Bytes()
      Dim latin1 = Text.Encoding.GetEncoding(&H6FAF)
      Return Encoding.Convert(Encoding.UTF8, latin1, bytes)
    End Function
    

    EDIT

    As Jon pointed out, it may be easier for people to remember the decimal number 28591 rather than the hex number &H6FAF.

提交回复
热议问题