去除UTF8文本中BOM标记

作者:追风剑情 发布于:2016-6-8 14:23 分类:C#

    public 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号