判断TXT文本的编码格式

function checkEncode(str : String) : String
{
if(!str) return “”;
var oriByteArr : ByteArray=new ByteArray();
oriByteArr.writeUTFBytes(str);
oriByteArr.position=0;
var b0 : int = oriByteArr.readUnsignedByte();
var b1 : int = oriByteArr.readUnsignedByte();
var fileType : String = “default”;
if(b0 == 0xFF && b1 == 0xFE) {
fileType = “Unicode”;
}else if(b0 == 0xFE && b1 == 0xFF) {
fileType = “Unicode big endian”;
}else if(b0 == 0xEF && b1 == 0xBB) {
fileType = “UTF-8”;
}else if(b0==0x5B&&b1==0x74){
fileType = “ANSI”;
}
return fileType;
}

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>