delphi获取各种编码的识别符


本文整理自网络,侵删。

 下面是常用编码的识别符, 在 Delphi(2009) 中如何获取呢?
Unicode: FF FE; BigEndianUnicode: FE FF; UTF8: EF BB BF
--------------------------------------------------------------------------------


var
bs: TBytes;
b: Byte;
str: string;
begin
{只有 Unicode、BigEndianUnicode、UTF8 编码有识别符}
bs := TEncoding.Unicode.GetPreamble;
str := '';
for b in bs do str := Format('%s %x', [str, b]);
ShowMessage(str); {FF FE}

bs := TEncoding.BigEndianUnicode.GetPreamble;
str := '';
for b in bs do str := Format('%s %x', [str, b]);
ShowMessage(str); {FE FF}

bs := TEncoding.UTF8.GetPreamble;
str := '';
for b in bs do str := Format('%s %x', [str, b]);
ShowMessage(str); {EF BB BF}

{ASCII、UTF7 和 Default(默认编码) 没有识别符}
bs := TEncoding.ASCII.GetPreamble;
str := '';
for b in bs do str := Format('%s %x', [str, b]);
ShowMessage(str); {无}

bs := TEncoding.UTF7.GetPreamble;
str := '';
for b in bs do str := Format('%s %x', [str, b]);
ShowMessage(str); {无}

bs := TEncoding.Default.GetPreamble;
str := '';
for b in bs do str := Format('%s %x', [str, b]);
ShowMessage(str); {无}
end;

相关阅读 >>

Delphi case 语句中使用字符串

isnumeric 判断字符串是否为数字

Delphi xe8安卓下汉字转gb2312 urlencode代码

Delphi之屏幕和窗口的坐标

Delphi 关闭icesword等

Delphi配置文件ini

Delphi 压缩与修复access数据库

Delphi复制文件时,如何显示进度条

Delphi 苹果系统弹出链接

Delphi 正则表达式的匹配模式

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...