查看字符串在不同编码(ASCII、Unicode、UTF7、UTF8、Default、BigEndianUnicode)下的 Hex
2008-09-05 10:33
1176 查看
本例效果图:
![](http://images.cnblogs.com/cnblogs_com/del/153653/o_8951.gif)
代码文件:
窗体文件:
![](http://images.cnblogs.com/cnblogs_com/del/153653/o_8951.gif)
代码文件:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Memo1: TMemo; Memo2: TMemo; Panel1: TPanel; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Button6: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} {从字符串到十六进制的函数} function StrToHex(str: string; AEncoding: TEncoding): string; var ss: TStringStream; i: Integer; begin Result := ''; ss := TStringStream.Create(str, AEncoding); for i := 0 to ss.Size - 1 do Result := Result + Format('%.2x ', [ss.Bytes[i]]); ss.Free; end; procedure TForm1.Button1Click(Sender: TObject); begin Memo2.Text := StrToHex(Memo1.Text, TEncoding.ASCII); end; procedure TForm1.Button2Click(Sender: TObject); begin Memo2.Text := StrToHex(Memo1.Text, TEncoding.Unicode); end; procedure TForm1.Button3Click(Sender: TObject); begin Memo2.Text := StrToHex(Memo1.Text, TEncoding.UTF7); end; procedure TForm1.Button4Click(Sender: TObject); begin Memo2.Text := StrToHex(Memo1.Text, TEncoding.UTF8); end; procedure TForm1.Button5Click(Sender: TObject); begin Memo2.Text := StrToHex(Memo1.Text, TEncoding.Default); end; procedure TForm1.Button6Click(Sender: TObject); begin Memo2.Text := StrToHex(Memo1.Text, TEncoding.BigEndianUnicode); end; procedure TForm1.FormCreate(Sender: TObject); begin Button1.Caption := 'To ASCII'; Button2.Caption := 'To Unicode'; Button3.Caption := 'To UTF7'; Button4.Caption := 'To UTF8'; Button5.Caption := 'To Default'; Button6.Caption := 'To BigEndianUnicode'; end; end.
窗体文件:
object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 156 ClientWidth = 353 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object Memo1: TMemo Left = 0 Top = 0 Width = 145 Height = 88 Align = alLeft Lines.Strings = ( 'Memo1') ScrollBars = ssVertical TabOrder = 0 end object Memo2: TMemo Left = 157 Top = 0 Width = 196 Height = 88 Align = alRight Lines.Strings = ( 'Memo2') ScrollBars = ssVertical TabOrder = 1 end object Panel1: TPanel Left = 0 Top = 88 Width = 353 Height = 68 Align = alBottom TabOrder = 2 object Button1: TButton Left = 16 Top = 6 Width = 73 Height = 25 Caption = 'Button1' TabOrder = 0 OnClick = Button1Click end object Button2: TButton Left = 95 Top = 6 Width = 74 Height = 25 Caption = 'Button2' TabOrder = 1 OnClick = Button2Click end object Button3: TButton Left = 175 Top = 6 Width = 82 Height = 25 Caption = 'Button3' TabOrder = 2 OnClick = Button3Click end object Button4: TButton Left = 263 Top = 6 Width = 74 Height = 25 Caption = 'Button4' TabOrder = 3 OnClick = Button4Click end object Button5: TButton Left = 16 Top = 37 Width = 96 Height = 25 Caption = 'Button5' TabOrder = 4 OnClick = Button5Click end object Button6: TButton Left = 130 Top = 37 Width = 207 Height = 25 Caption = 'Button6' TabOrder = 5 OnClick = Button6Click end end end
相关文章推荐
- 查看字符串在不同编码(ASCII、Unicode、UTF7、UTF8、Default、BigEndianUnicode)下的 Hex
- 编码格式-Ascii、Default、Unicode、BigEndianUnicode、UTF7、UTF8
- C/C++ 各种字符编码字符串的转换 可用于XML文件的字符转化读写 (收集 GBK - UTF8 - Unicode - ANSI )
- UNICODE含中文编码字符串转换UTF8中文字符串
- Python基础---字符串编码(Unicode, UTF-8, ASCII)
- 字符串编码问题(Ascii、Unicode、UCS-2、GBK、UTF-8)
- 聊聊计算机中的编码(Unicode,GBK,ASCII,utf8,utf16,ISO8859-1等)以及乱码问题的解决办法
- ASCII,Unicode,UTF8编码的认识
- 【转】【编码】ANSI,ASCII,Unicode,UTF8之一
- 字符串和编码(ASCII 、Unicode、UTF-8)
- ASCII-->Ansi-->Unicode-->UTF8 关于编码 自己的总结
- Unicode、ASCII、UTF7、UTF8、UTF16、UTF32
- 关于编码: ascii(ansi), gb-2312, unicode, utf8
- 所谓编码--泛谈ASCII、Unicode、UTF8、UTF16、UCS-2等编码格式
- 字符编码【utf8,unicode,ANSI,ascii】
- Ansi、Unicode、UTF8等编码字符串之间的转换和写入文本文件(学习中……)
- python:正确的对未知编码的字符串进行预处理-Unicode-UTF8-gbk
- ASCII、Unicode、UTF8编码类型的理解
- 关于编码: ascii(ansi), gb-2312, unicode, utf8(续)
- ASCII,DBCS(GBK),unicode,utf8编码规范的区别