首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

PB怎么判断一个txt文件的编码方式

2012-03-16 
PB如何判断一个txt文件的编码方式RT,谢谢帮忙。[解决办法]读上文件的头两个字节case 0xefbb: //UTF-8brea

PB如何判断一个txt文件的编码方式
RT,谢谢帮忙。

[解决办法]
读上文件的头两个字节
case 0xefbb: //"UTF-8"
break;
case 0xfffe: // unicode小端格式
break;
case 0xfeff: //"Unicode big endian"
break;
default: //ANSI
break;
[解决办法]
收藏,QQQ
[解决办法]
mark!学习了
[解决办法]
1#说得倒不错,可惜不是pb的语法

//f_gettxtcode 判断文本的编码格式
//参数 string as_filename 文件名
//返回如下
/*
开头字节 Charset/encoding

EF BB BF UTF-8
FE FF UTF-16/UCS-2, little endian
FF FE UTF-16/UCS-2, big endian
FF FE 00 00 UTF-32/UCS-4, little endian.
00 00 FE FF UTF-32/UCS-4, big-endian.
*/
integer li_FileNum,li_bytes
li_FileNum = FileOpen(as_filename, StreamMode!)
long ll_first[]
blob lb_data
li_bytes = FileRead(li_FileNum, lb_data)
ll_first[1]=asc(string(blobmid(lb_data,1,1)))
ll_first[2]=asc(string(blobmid(lb_data,2,1)))
ll_first[3]=asc(string(blobmid(lb_data,3,1)))
ll_first[4]=asc(string(blobmid(lb_data,4,1)))

if ll_first[1]=239 and ll_first[2]=187 and ll_first[3]=191 then
return 1//utf-8
end if
if ll_first[1]=254 and ll_first[2]=255 then
return 2//utf-16
end if
if ll_first[1]=255 and ll_first[2]=254 then
return 3//utf-16
end if
if ll_first[1]=255 and ll_first[2]=254 and ll_first[3]=0 and ll_first[4]=0 then
return 4//utf-32
end if
if ll_first[1]=0 and ll_first[2]=0 and ll_first[1]=254 and ll_first[2]=255 then
return 5//utf-32
end if

return 0//ansi
[解决办法]
学习了,顶!

热点排行