





























代码
#region 判断Url参数是否UTF8编码
public static bool IsUTF8(string url)
{
byte[] buf = GetUrlCodingToBytes(url);
return IsTextUTF8(buf);
}
private static bool IsTextUTF8(byte[] buf)
{
int i;
byte cOctets = 0; // octets to go in this UTF-8 encoded character
bool bAllAscii = true;
long iLen = buf.Length;
for (i = 0; i < iLen; i++)
{
if ((buf[i] & 0x80) != 0) bAllAscii = false;if (cOctets == 0)
{
if (buf[i] >= 0x80)
{
do
{
buf[i] <<= 1;
cOctets++;
}
while ((buf[i] & 0x80) != 0);
cOctets
--;urlCoding
= urlCoding.Replace("%", string.Empty);UTF-8编码规则参考
http://blog.csdn.net/sandyen/archive/2006/08/23/1108168.aspx
上面代码是网络上找的,不过存在大部分不能识别的情况,后根据对于中文,UTF8 一定编码成 3 字节,这个原则
修改了一下,现在大部分情况下都能正确识别
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。