using System.Text;
class TextEncoding
{
public readonly static Encoding Utf8 = Encoding.UTF8;
public readonly static Encoding Utf8Bom = new UTF8Encoding(true);
public readonly static Encoding Utf8NoBom = new UTF8Encoding(false);
public readonly static byte[] Utf8BomBytes = { 0xEF, 0xBB, 0xBF };
public static bool HasBom(byte[] bytes)
=> bytes[0] == Utf8BomBytes[0] && bytes[1] == Utf8BomBytes[1] && bytes[2] == Utf8BomBytes[2];
public static string GetUtf8RemovedBomString(byte[] bytes)
{
if (HasBom(bytes))
return Utf8.GetString(bytes, 3, bytes.Length - 3);
return Utf8.GetString(bytes);
}
}
07-05
737
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交