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

后端 未结 5 1841
星月不相逢
星月不相逢 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 22:46

    Dont know if this should be posted here but i made a small function in C# to check if a string support the target encoding type.

    Hope it can be of any help...

    /// 
    /// Function for checking if a string can support the target encoding type
    /// 
    /// The text to check
    /// The target encoding
    /// True if the encoding supports the string and false if it does not
    public bool SupportsEncoding(string text, Encoding targetEncoding)
    {
        var btext = Encoding.Unicode.GetBytes(text);
        var bencodedtext = Encoding.Convert(Encoding.Unicode, targetEncoding, btext);
    
        var checktext = targetEncoding.GetString(bencodedtext);
        return checktext == text;
    }
    
    //Call the function demo with ISO-8859-1/Latin-1
    if (SupportsEncoding("some text...", Encoding.GetEncoding("ISO-8859-1")))
    {
        //The encoding is supported
    }
    else
    {
        //The encoding is not supported 
    }
    

提交回复
热议问题