手机
当前位置:查字典教程网 >编程开发 >C#教程 >utf8编码检测方法分享
utf8编码检测方法分享
摘要:复制代码代码如下:publicboolisUtf8(byte[]rawText){boolresult=true;if(rawText==n...

复制代码 代码如下:

public bool isUtf8(byte[] rawText)

{

bool result = true;

if (rawText == null)

{

return !result;

}

int pos = 0;

while (pos < rawText.Length && result)

{

if ((rawText[pos] & 0x7F) == rawText[pos])

{

pos++;

}

else

{

int bitLen = 7;

while (((rawText[pos] >> bitLen) & 0x01) == 1 && bitLen > 0)

{

bitLen--;

}

int byteCount = 7 - bitLen;

if (byteCount > 1 && byteCount < 7)

{

for (int i = 1; i < byteCount; ++i)

{

if (pos + i >= rawText.Length || (rawText[pos + i] & 0xBF) != rawText[pos + i])

{

result = false;

break;

}

}

pos += byteCount;

}

else

{

result = false;

}

}

}

return result;

}

【utf8编码检测方法分享】相关文章:

C#线程池用法详细介绍

C# 透明窗体制作实现方法比较分析

C#利用子线程刷新主线程分享教程

C#异步调用的好处和方法分享

string类的使用方法详解

C#编程实现Excel文档中搜索文本内容的方法及思路

c#防止多次运行代码收集分享

c# datetime方法应用介绍

使用异步方式调用同步方法(实例详解)

C#中几个未知的Visual Studio编码技巧分享

精品推荐
分类导航