去除文本中的BOM标记

作者:追风剑情 发布于:2015-6-3 11:40 分类:C#

// 去除UTF8文本中BOM标记
    public static string TrimBOM(string fileText)
    {
        if (string.IsNullOrEmpty(fileText))
            return "";

        byte[] bytes = Encoding.UTF8.GetBytes(fileText);
        if (bytes.Length >= 3 && bytes[0] == 239 && bytes[1] == 187 && bytes[2] == 191)
        {
            fileText = Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3);
        }

        return fileText;
    }

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号