七星彩开奖结果对比器:判断字符串的编码类型(GBK / UTF8)
来源:百度文库 编辑:中财网 时间:2024/04/28 14:45:53
GBK:_____________________________________________________________int isgbk(char *s, size_t ns)
{
if(ns > 2 && (uint8_t)*s >= 0x81 && (uint8_t)*s <= 0xfe
&& (
((uint8_t)*(s+1) >= 0x80 && (uint8_t)*(s+1) <= 0x7e)
|| ((uint8_t)*(s+1) >= 0xa1 && (uint8_t)*(s+1) <= 0xfe)
)
)
{
return 1;
}
return 0;
}_______________________________________________________________ bool isGBKCode(const string& strIn)
{
unsigned char ch1;
unsigned char ch2;
if (strIn.size() >= 2)
{
ch1 = (unsigned char)strIn.at(0);
ch2 = (unsigned char)strIn.at(1);
if (ch1>=129 && ch1<=254 && ch2>=64 && ch2<=254)
return true;
else return false;
}
else return false;
}
______________________________________________________________ UTF8: ______________________________________________________________int isutf8(char *s, size_t ns)
{
uint8_t x = 0, i = 0, j = 0, nbytes = 0, n = 0;
for(i = 1; i < 7; i++)
{
x = (uint8_t)(255 << i);
if(((uint8_t)*s & x) == x)
{
n = nbytes = (8 - i);
for(j = 0; (j < nbytes && j < ns); j++)
{
if((uint8_t)s[j] <= 0x80 && (uint8_t)s[j] >= 0xc0)break;
else n--;
}
if(n == 0) return nbytes;
}
}
return 0;
}
{
if(ns > 2 && (uint8_t)*s >= 0x81 && (uint8_t)*s <= 0xfe
&& (
((uint8_t)*(s+1) >= 0x80 && (uint8_t)*(s+1) <= 0x7e)
|| ((uint8_t)*(s+1) >= 0xa1 && (uint8_t)*(s+1) <= 0xfe)
)
)
{
return 1;
}
return 0;
}_______________________________________________________________ bool isGBKCode(const string& strIn)
{
unsigned char ch1;
unsigned char ch2;
if (strIn.size() >= 2)
{
ch1 = (unsigned char)strIn.at(0);
ch2 = (unsigned char)strIn.at(1);
if (ch1>=129 && ch1<=254 && ch2>=64 && ch2<=254)
return true;
else return false;
}
else return false;
}
______________________________________________________________ UTF8: ______________________________________________________________int isutf8(char *s, size_t ns)
{
uint8_t x = 0, i = 0, j = 0, nbytes = 0, n = 0;
for(i = 1; i < 7; i++)
{
x = (uint8_t)(255 << i);
if(((uint8_t)*s & x) == x)
{
n = nbytes = (8 - i);
for(j = 0; (j < nbytes && j < ns); j++)
{
if((uint8_t)s[j] <= 0x80 && (uint8_t)s[j] >= 0xc0)break;
else n--;
}
if(n == 0) return nbytes;
}
}
return 0;
}
php中utf-8编码改成gbk的方法
GBK编码和UTF-8会不会起冲突
在vb中如何编写程序使得utf-8编码转为gbk编码
关于utf-8编码的问题
ASP里UTF-8编码的问题
UTF-8编码是怎么回事?
如何判断一个字符串是否是unicode编码?
怎样知道某个汉字的UTF-8编码?
计算机里中文编码有哪些?什么UTF***的
浏览器浏览UTF-8编码的网站时缺字
菜习中的编码类型GB2312和UTF-8有什么区别 他们是什么意思
怎么把编码gb2312转到gbk编码?
有什么方法能把UTF-8的编码批量转换成ANSI的编码
求一个可以批量把UTF-8编码的文本文件转换成ANSI编码的软件
谁有将GB2312编码转换成UTF-8编码的PHP类
Gb2312编码转换到Utf-8编码
vbscript 判断汉字的编码
php中关于字符GBK转utf-8
皮肤类型的判断
皮肤类型的判断
编码GB2312和GBK有什么关系
vc中如何使用GBK编码
我是用编码gbk还是utf8
字符串的合法文件怎么判断?